Introduction: This is the code to implement Rungi Kutta Method, which is important concept of numerical methods subject, by using matlab software. You can change the code to get desired results. Codefunction [k]= rungi(u,v,h) n=(v-u)/h; y(1)=1; f=1; for q= u:h:v x(f)=q; f=f+1; end for f=1:n+1 answer(f,1)=x(f); end for c=2:n+1 k1=h*(x(c-1)+y(c-1)); k2=h*((x(c-1)+h/2)+(y(c-1)+k1/2)); k3=h*((x(c-1)+h/2)+(y(c-1)+k2/2)); k4=h*((x(c-1)+h)+(y(c-1)+k3)); y(c)=y(c-1)+(1/6)*(k1+2*k2+2*k3+k4); end for r=1:n+1 m(r)=2*exp(x(r))-x(r)-1; end for c=1:n+1 answer(c,2)=y(c); end for r=1:n+1 answer(r,3)=m(r); end for t=1:n+1 answer(t,4)=m(t)-y(t); end answer end OutPut
0 Comments
Introduction: This is the code to implement Romberg Integration Formula, which is important concept of numerical methods subject, by using matlab software. You can change the code to get desired results. Codefunction [z]= romberg(u,v,h) h1=v-u; f=1; for q= u:h:v x(f)=q; f=f+1; end w=length(x); x r=1; for q=1:w fx(r)=exp(x(q)*x(q)); r=r+1; end fx I11=0.5*(fx(1)+fx(w)); T11=h1*I11; a=u+h1/2; a1=((a-u)/h)+1; a2=round(a1); I12=I11+fx(a2); T12=(h1/2)*I12; b=(u+3*h1/4); b1=((b-u)/h)+1; b2 = round(b1); c=(u+h1/4); c1=((c-u)/h)+1; c2=round(c1); I13=I12+fx(b2)+fx(c2); T13=h1/4*I13; d=(u+h1/8); d1=((d-u)/h)+1; d2=round(d1); e=(u+3*h1/8); e1=((e-u)/h)+1; e2=round(e1); g=(u+5*h1/8); g1=((g-u)/h)+1; g2=round(g1); i=(u+7*h1/8); i1=((i-u)/h)+1; i2=round(i1); I14=(I13+fx(d2)+fx(e2)+fx(g2)+fx(i2)); T14=h1/8*I14; T22=T12+(1/3)*(T12-T11); T23=T13+(1/3)*(T13-T12); T24=T14+(1/3)*(T14-T13); T33=T23+(1/15)*(T23-T22); T34=T24+(1/15)*(T24-T23); T44=T34+(1/63)*(T34-T33); T44 end OutPutIntroduction: This is the code to implement Trapezoidal Rule, which is important concept of numerical methods subject, by using matlab software. You can change the code to get desired results. Codefunction [z]= trapizidal(x,y,h) f=1; for q= x:h:y x(f)=q; f=f+1; end w=length(x); x r=1; for q=1:w fx(r)=x(q)+4; r=r+1; end fx v=fx(1)+fx(w); p=0; for q=2:1:(w-1) p=p+fx(q); end z=(h/2)*(v+(2*p)); end OutPutIntroduction: This is the code to implement Stirling's Interpolation Formula, which is important concept of numerical methods subject, by using matlab software. You can change the code to get desired results. Codet=[1.2 1.4 1.6 1.8 2.0]; o=[5.64642 6.44218 7.17356 7.83327 8.41471]; dt=zeros(5,6); for i=1:5 dt(i,1)=t(i); dt(i,2)=o(i); end n=4; for j=3:6 for i=1:n dt(i,j)=dt((i+1),(j-1))-dt(i,(j-1)) end n=n-1; end h=t(2)-t(1) tp=27; for i=1:5 q=(tp-t(i))/h; if(q>(-0.25)&&q<(0.25)) p=q; end end p l=tp-(p*h) for i=1:5 if(l==t(i)) r=i; end end f0=o(r); f11=dt((r-1),3); f12=dt((r+1),3); f02=dt((r-1),4); f31=dt((r-2),5); f32=dt((r-1),5); f04=dt((r-2),6); fp=f0+(p*(f11+f12))/2+((p*p)*f02)/2+(p*((p*p)-1)*(f31+f32))/12+((p*p)*((p*p)-1)*f04)/24 OutPut
Introduction: This is the code to implement Euler Formula To Solve Ordinary Differential Equations, which is important concept of numerical methods subject, by using matlab software. You can change the code to get desired results. Codefunction [output]=question1(a,b,h); u=1; for i=a:h:b arrayOfX(u)=i; u=u+1; end lengthOfX=length(arrayOfX); v=1; for j=1:1:lengthOfX arrayOfY(j)=2*exp(arrayOfX(j))-(arrayOfX(j)+1); v=v+1; end for k=1:1:lengthOfX valuesOfFunction(k)=arrayOfX(k)+arrayOfY(k); arrayOfY(k)=2*exp(arrayOfX(k))-(arrayOfX(k)+1); arrayOfL(k)=arrayOfX(k)+h; arrayOfC(k)=arrayOfY(k)+h*valuesOfFunction(k); valuesOfFunction2(k)=arrayOfL(k)+arrayOfC(k); arrayOfN(k)=arrayOfX(k)+(h/2); arrayOfB(k)=arrayOfY(k)+(h/2)*valuesOfFunction(k); valuesOfFunction3(k)=arrayOfN(k)+arrayOfB(k); byEulerMethod(k)=arrayOfY(k)+h*valuesOfFunction(k); byImprovedEulerMethod(k)=arrayOfY(k)+(h/2)*(valuesOfFunction(k)+valuesOfFunction2(k)); byModifiedEulerMethod(k)=arrayOfY(k)+h*(valuesOfFunction3(k)); end errorEuler=arrayOfY(lengthOfX)-byEulerMethod(lengthOfX-1); errorImprovedEuler=arrayOfY(lengthOfX)-byImprovedEulerMethod(lengthOfX-1); errorModifiedEuler=arrayOfY(lengthOfX)-byModifiedEulerMethod(lengthOfX-1); t=zeros(lengthOfX,10); i=0; t(1,1)=i; i=1; for d=2:lengthOfX t(d,1)=i; i=i+1; end for g=1:lengthOfX t(g,2)=arrayOfX(g); t(g,3)=arrayOfY(g); t(g,4)=byEulerMethod(g); t(g,5)=byImprovedEulerMethod(g); t(g,6)=byModifiedEulerMethod(g); end t errorEuler errorImprovedEuler errorModifiedEuler end OutPut4th column shows result using Euler method, 5th column shows result using Improved Euler Method and 6th column shows result using Modified Euler Method
Introduction: This is the code to implement Simpson's 1/3rd Rule, which is important concept of numerical methods subject, by using matlab software. You can change the code to get desired results. Codefunction [z]= simpson(x,y,h) f=1; for q= x:h:yx(f)=q; f=f+1; end w=length(x); x r =1; for q=1:wfx(r)=(x(q)+5); r =r+1; end fx v=fx(1)+fx(w); p=0; o=0; for q=2:(w-1)if(rem(q,2)==0) p=p+fx(q); end if(rem(q,2)~=0) o=o+fx(q); end end z=(h/3)*(v+(4*p)+(2*o)); OutPutIntroduction: This is the code to implement newton's backward interpolation formula, which is important concept of numerical methods subject, by using matlab software. You can change the code to get desired results. Codex=[0 8 16 24 32 40]; fx=[14.621 11.843 9.870 8.418 7.305 6.413]; dt=zeros(6,7); for i=1:6 dt(i,1)=x(i); dt(i,2)=fx(i); end n=5; for j=3:7 for i=1:n dt(i,j)=dt(i+1,j-1)-dt(i,j-1) end n=n-1; end h=x(2)-x(1) xp=27; for i=1:6 q=(xp-x(i))/h; if (q>0&&q<1) p=q; end end p l=xp-(p*h) for i=1:6 if(l==x(i)) r=i; end end f0=fx(r); f01=dt((r-1),3); f02=dt((r-2),(3+1)); f03=dt((r-3),(3+2)); f04=dt((r-4),(3+3)); fp=(f0)+((p*f01)+(p*(p+1)*f02)/(2)) + ((p*(p+1)*(p+2)*f03)/(6)) OutPut
MATLAB CODE - NEWTON'S FORWARD INTERPOLATION FORMULA - NUMERICAL METHODS
This is the code to implement newton's forward interpolation formula, which is important concept of numerical methods subject, by using matlab software. You can change the code to get desired results.
Codex=[0 2 4 7 10 12]; fx=[20 20 12 7 6 6]; dt=zeros(6,10); for i=1:6 dt(i,1)=x(i); dt(i,2)=fx(i); end n=5; for j=3:10 for i=1:n dt(i,j)=dt(i+1,j-1)-dt(i,j-1) end n=n-1; end h=x(2)-x(1) xp=1.5; for i=1:5 q=(xp-x(i))/h; if (q>0&&q<1) p=q; end end p l=xp-(p*h) for i=1:5 if(l==x(i)) r=i; end end f0=fx(r); f01=dt(r,3); f02=dt(r,(3+1)); f03=dt((r),(3+2)); f04=dt((r),(3+3)); fp=(f0)+((p*f01)+(p*(p-1)*f02)/(2)) + ((p*(p-1)*(p-2)*f03)/(6))+((p*(p-1)*(p-2)*(p-3)*f04)/(24)) OutPut
Difference Table Matlab Code : Introduction
Difference table is important concept of numerical methods/analysis. Here matlab code to produce difference table automatically is presented. This code produces table of predefined values. But you can also produce your own difference table by a little change in code. Codex=[-1 0 1 2 3 4 5 6 7]; fx=[-3 -1 5 27 77 167 309 515 797]; dt=zeros(9,10); for i=1:9 dt(i,1)=x(i) dt(i,2)=fx(i) end n=8; for j=3:9 for i=1:n dt(i,j)=dt(i+1,j-1)-dt(i,j-1) end n=n-1; end OutPut
|
Categories
All
Archives
March 2014
This section will not be visible in live published website. Below are your current blog design settings: Current Number Of Columns are = 1 Blog Post Style = card Use of custom card colors instead of default colors = Blog Post Card Background Color = current color Blog Post Card Shadow Color = current color Blog Post Card Border Color = current color Use of custom colors instead of theme colors for below options= Blog Post Title Color = current color Blog Post Title Hover Color = current color Blog Post Date Color = current color Blog Post Date Hover Color = current color Blog Post Read More Link Color = current color Blog Post Read More Link Hover Color = current color Blog Post Comments Count Color = current color Blog Post Comments Count Hover Color = current color |