February 7, 2017 | Author: Reza Abazari | Category: N/A
Download Numerical Mathematics With MATLAB...
Numerical Mathematics with
MATLAB
Reza Abazari 2008
Contents 1. Rootfinding for Nonlinear Equations ...…......………….………………….1-38 2. Numerical Linear Algebra ……………………………….……..…………..40-76 3. Polynomial Interpolation ………………………………….….……………78-102 4. Numerical Integration ………………………..…………….…………..…104-137 5. Nonlinear Systems and Numerical Optimization ……..….………….139-169 6. Numerical solution of ODE ………………….…………….…………….171-199 7. Numerical solution of PDE …………………..……………..……………201-235
2
1. Rootfinding for Nonlinear Equations function R = approot (f,X,epsilon) % Input - f is object function % - X is the vector of abscissas % - epsilon is the tolerance % Output - R is the vector of approximate locations for roots % If f is an M-file function call R = approot (@f,X,epsilon). % If f is an anonymous function call R = approot (f,X,epsilon). % Copyright by Reza Abazari 2008-04-23 % Email :
[email protected] Y=f(X); yrange = max(Y)-min(Y); epsilon2 = yrange*epsilon; n=length(X); m=0; X(n+1)=X(n); Y(n+1)=Y(n); for k=2:n if Y(k-1)*Y(k) 0 \n' ); else while 1 it = it + 1; b = (a + c)/2; Y_b = feval(f_name, b ); plot([b,b],[Y_b,0],':'); plot(b,0,'o') if it0'), return, end for k=1:max1 dx=yb*(b-a)/(yb-ya); c=b-dx; ac=c-a; yc=f(c); if yc==0,break; elseif yb*yc>0 b=c; yb=yc; else a=c; ya=yc; end dx=min(abs(dx),ac); if abs(dx)