Advertisement
kaburen

stycznev2

Apr 9th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.33 KB | None | 0 0
  1. function [wyn] = met_styczv2(g,x0)
  2. %('x^2+x-1',-1) % Miejsce zerowe: -1.6180 oraz 0.6180
  3. syms x;
  4. ep = 0.001;
  5. f = @(x)eval(g);
  6. z = diff(eval(g));
  7. fp = @(x)eval(z);
  8.  
  9. for i = 1:10
  10.        x1 = x0 - f(x0)/fp(x0);  
  11.        if(abs(f(x0)-f(x1))<ep)
  12.            break
  13.        end        
  14.        x0 = x1;          
  15. end
  16. wyn = x0;
  17. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement