Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Example 3. Newton’s method
- clear all, close all, clc
- format longG
- x=-1:0.01:6;
- f=@(x)1/2*(x-1) + 1/2*(y+2);
- f=@(x)sin(x+2) - y;
- plot(x,f(x),'r','LineWidth',3)
- grid
- figure
- x=0.8:0.01:1.2;
- plot(x,f(x),'r','LineWidth',3)
- % Example 2 (continuation)
- XN=[0.92 1.08 3]; % initial approximations
- iter=5; % maximum number of iterations
- syms x, fder(x)=diff(f(x),x);
- for j=1:3
- xn=XN(j);
- for i=1:iter
- xn=xn-f(xn)/double(fder(xn));
- M(i,1)=xn; M(i,2)=f(xn);
- end
- disp('initial approximation:'),disp(XN(j))
- disp(' x f(x)')
- disp(M)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement