Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. %% Example 3. Newton’s method
  2. clear all, close all, clc
  3. format longG
  4. x=-1:0.01:6;
  5. f=@(x)1/2*(x-1) + 1/2*(y+2);
  6. f=@(x)sin(x+2) - y;
  7. plot(x,f(x),'r','LineWidth',3)
  8. grid
  9.  
  10. figure
  11. x=0.8:0.01:1.2;
  12. plot(x,f(x),'r','LineWidth',3)
  13.  
  14. % Example 2 (continuation)
  15. XN=[0.92 1.08 3]; % initial approximations
  16. iter=5; % maximum number of iterations
  17. syms x, fder(x)=diff(f(x),x);
  18. for j=1:3
  19. xn=XN(j);
  20. for i=1:iter
  21. xn=xn-f(xn)/double(fder(xn));
  22. M(i,1)=xn; M(i,2)=f(xn);
  23. end
  24. disp('initial approximation:'),disp(XN(j))
  25. disp(' x f(x)')
  26. disp(M)
  27. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement