Advertisement
kaburen

styczne

Apr 3rd, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.34 KB | None | 0 0
  1. function [wyn] = met_stycz(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. fp = diff(eval(g));
  7.  
  8. for i = 1:10          
  9.        f1 = subs(fp,x0);
  10.        x1 = x0 - f(x0)/f1;  
  11.        if(abs(f(x0)-f(x1))<ep)
  12.            break
  13.        end        
  14.        x0 = x1;          
  15. end
  16. wyn = eval(x0);
  17. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement