Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 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)(0.4).*x - 3- cos(3.*x);
  6. plot(x,f(x),'r','LineWidth',3)
  7. grid
  8.  
  9. figure
  10. x=0.8:0.01:1.2;
  11. plot(x,f(x),'r','LineWidth',3)
  12.  
  13. % Example 2 (continuation)
  14. XN=[0.92 1.08 3]; % initial approximations
  15. iter=6; % maximum number of iterations
  16. syms x, fder(x)=diff(f(x),x);
  17. for j=1:3
  18. xn=XN(j);
  19. for i=1:iter
  20. xn=xn-f(xn)/double(fder(xn));
  21. M(i,1)=xn; M(i,2)=f(xn);
  22. end
  23. disp('initial approximation:'),disp(XN(j))
  24. disp(' x f(x)')
  25. disp(M)
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement