Advertisement
cyphric

Untitled

Oct 24th, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. clc
  2. clear all
  3. z = -2:0.01:2;
  4. plot(z,f(z)); grid on;
  5. x = (0);
  6. z = (-1.5);
  7. y = zeros();
  8. count = 0;
  9. for i = 1:100
  10. x = [x,fix(x(i))];
  11. disp(x(i)); format longg;
  12. z = [z,newton(z(i))];
  13. disp(z(i));
  14. errorx = abs(x(i) - x(1));
  15. errorz = abs(z(i) - z(1));
  16.  
  17. end
  18.  
  19. function fi = fix(x)
  20. fi = (-exp(-x) + 2*x^3)/5;
  21. end
  22. function fun = f(x)
  23. fun = exp(-x) -2.*x.^3 + 5.*x;
  24. end
  25.  
  26. function der = deriv(x)
  27. der = -exp(-x) -6.*x.^2 + 5;
  28. end
  29.  
  30. function new = newton(x)
  31. new = x - (f(x)/deriv(x));
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement