Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc
- clear all
- z = -2:0.01:2;
- plot(z,f(z)); grid on;
- x = (0);
- z = (-1.5);
- y = zeros();
- count = 0;
- for i = 1:100
- x = [x,fix(x(i))];
- disp(x(i)); format longg;
- z = [z,newton(z(i))];
- disp(z(i));
- errorx = abs(x(i) - x(1));
- errorz = abs(z(i) - z(1));
- end
- function fi = fix(x)
- fi = (-exp(-x) + 2*x^3)/5;
- end
- function fun = f(x)
- fun = exp(-x) -2.*x.^3 + 5.*x;
- end
- function der = deriv(x)
- der = -exp(-x) -6.*x.^2 + 5;
- end
- function new = newton(x)
- new = x - (f(x)/deriv(x));
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement