




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





Program for Fixed point Method function r =myfixed(x0,tol,n) for i=1:n x=g(x0); if abs (x-x0) < tol break end x0=x; end r=x; function y=g(x) y=x^2;
myfixed(1,0.00001,10000) ans = 1 myfixed(0,0.00001,10000) ans = 0
Program for Newton Method function r =mynewt(x0,tol,n) for i=1:n x=x0-f(x0)/fd(x0); if abs (x-x0) < tol break end x0=x; end r=x; function y=f(x) y=x^2-4; function t=fd(x) t=2*x; r =mynewt(1,0.00001,10000) r = 2.
function r =mytrip(a,b,n) h=(b-a)/n; sum =0; for i=1:n- sum = sum +f(a+ih); end I =h/2(2* sum +f(a)+f(b)); disp('the integeration of the function =') disp(I) function y=f(x) y=x; >> mytrip(0,1,10) the integeration of the function = 0.
function r=mysimp(a,b,n) h=(b-a)/n; sum1 =0; for i=1:2:n- sum1 = sum1 +f(a+ih); end sum2 = 0; for i=2:2:n- sum2 = sum2+f(a+ih); end I =h/3(4sum1 +2* sum2 +f(a)+f(b)); disp('the integeration of the function =') disp(I) function y=f(x) y=x; >> mysimp(0,1,10) the integeration of the function = 0.
Program for Range Kutta 4 Method function y = myrk4(a,b,n,alpha) f=inline('1-ty'); t(1)=a; y(1)=alpha; h =(b-a)/n; for i = 1 : n k1 = hf(t(i),y(i)); k2 = hf(t(i) + h/2, y(i) + k1/2); k3 = hf(t(i) + h/2, y(i) + k2/2); k4 = hf(t(i) + h, y(i) + k3); y(i+1) = y(i) + (k1 + 2(k2 + k3) + k4) / 6.0; t(i+1)=a+i*h; end >>myrk4(0.0,5.0,25,1.0) ans = Columns 1 through 6 1.0000 1.1776 1.3024 1.3682 1.3755 1. Columns 7 through 12 1.2473 1.1373 1.0147 0.8912 0.7753 0. Columns 13 through 18 0.5842 0.5112 0.4519 0.4043 0.3661 0. Columns 19 through 24 0.3098 0.2887 0.2708 0.2553 0.2418 0. Columns 25 through 26 0.2190 0.