Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. function [] = secant_method()
  2. cn = [1,-1,-2];
  3. a = 1.5;
  4. b = 2.5;
  5. k = 1;
  6.  
  7. n(k) = (polyval(cn,b)*a - polyval(cn,a) *b )/ (polyval(cn,b)- polyval(cn,a));
  8.  
  9. %if (round(n(k),1) == 2)
  10. n(k),
  11. %end
  12.  
  13.  
  14. approximate_error(k) = abs(n(k) - 2)/2,
  15. k=k+1;
  16.  
  17. n(k) = (polyval(cn,n(k-1))*b - polyval(cn, b) * n(k-1))/ (polyval(cn, n(k-1)) - polyval(cn,b));
  18.  
  19. %if(round(n(k),1) == 2)
  20. n(k),
  21. %end
  22.  
  23.  
  24. approximate_error(k) = abs(n(k) - 2)/2,
  25.  
  26. while(k < 10)
  27. n(k+1) = polyval(cn, n(k))*n(k-1) - polyval(cn,n(k-1)*n(k))/ (polyval(cn, n(k)) - polyval(cn,n(k-1)));
  28.  
  29. approximate_error(k+1) = abs(n(k+1) - 2)/2,
  30. n(k+1),
  31. k=k+1;
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement