1. Chapter No. Two
Program 2.1
MATLAB m-file for the Bisection Method function sol=bisect(fn,a,b,tol) f a = f eval(f n, a); f b = f eval(f n, b); if f a∗f b > 0; fprintf(’Endpoints have same sign’) return end while abs (b − a) > tol c = (a + b)/2; f c = f eval(f n, c); if f a ∗ f c < 0; b = c; else a = c; end end; sol=(a + b)/2;
Program 2.2
MATLAB m-file for the Fixed-Point Method function sol=fixpt(fn,x0,tol) old= x0+1; while abs(x0-old) > tol; old=x0; x0 = f eval(f n, old); end; sol=x0;
Program 2.3
MATLAB m-file for the Newton’s Method function sol=newton(fn,dfn,x0,tol) old = x0+1; while abs (x0 − old) > tol; old = x0; x0 = old − f eval(f n, old)/f eval(df n, old); end; sol=x0;
Program 2.4
MATLAB m-file for the Secant Method function sol=secant(fn,a,b,tol) x0 = a; x1 = b; f a = f eval(f n, x0); f b = f eval(f n, x1); while abs(x1-old)> tol new = x1 − f b ∗ (x1 − x0)/(f b − f a); x0 = x1; f a = f b; x1 == new; f b = f eval(f n, new); end; sol=new;
1
Program 2.5
MATLAB m-file for first Modified Newton’s Method function sol=mnewton1(fn1,dfn1,x0,m,tol) old = x0+1; while abs (x0 − old) > tol; old = x0; fa=feval(fn,old); fb=feval(dfn,old); x0 = old − (m ∗ f a)/f b; end; sol=x0;
Program 2.6
MATLAB m-file for second Modified Newton’s Method function sol=mnewton2(fn1,dfn1,ddfn1,x0,tol) old = x0+1; while abs (x0 − old) > tol; old = x0; fa=feval(fn,old); fb=feval(dfn,old); fc=feval(ddfn,old); x0 = old − (f a ∗ f b)/((f b). ˆ 2 - (f a ∗ f c)); end; sol=x0;
Program 2.7
MATLAB m-file for Newton’s Method for a Nonlinear System function sol=newton2(fn2,dfn2,x0,tol) old=x0+1; while max(abs(x0-old))>tol; old=x0; f = f eval(f n2, old); f 1 = f (1); f 2 = f (2); J=feval(dfn2,old); f 1x = J(1, 1); f 1y = J(1, 2); f 2x = J(2, 1); f 2y = J(2, 2); D = f 1x ∗ f 2y − f 1y ∗ f 2x; h = (f 2 ∗ f 1y − f 1 ∗ f 2y)/D; k = (f 1 ∗ f 2x − f 2 ∗ f 1x)/D; x0 = old + [h, k]; end; sol=x0; 2. Chapter No. Three
Program 3.1
MATLAB m-file for finding inverse of a