Why do i only get 1 of 2 roots of this function when using Newtons method? What am i missing?
disp("Newton")
x = 0;
t = 1;
format short e
disp("x f(x) fprim(x) korr kvad linje")
while abs(t)>8e-8
f = 51.*x-((x.^2+x+0.03)/2.*x+1).^7-17.*x.*exp(-1.*x);
fp = 51 – 7.*((x.^2+x+0.3).^6).*(2.*x.^2+2.*x+0.4)/((2.*x+1).^8)-17.*(exp(-1.*x)-exp(-1.*x));
g=t;
t=f/fp;
kvad = t/g^2; linj = t/g;
disp([x f fp t kvad linj]);
x = x-t;
end
rot = x;disp("Newton")
x = 0;
t = 1;
format short e
disp("x f(x) fprim(x) korr kvad linje")
while abs(t)>8e-8
f = 51.*x-((x.^2+x+0.03)/2.*x+1).^7-17.*x.*exp(-1.*x);
fp = 51 – 7.*((x.^2+x+0.3).^6).*(2.*x.^2+2.*x+0.4)/((2.*x+1).^8)-17.*(exp(-1.*x)-exp(-1.*x));
g=t;
t=f/fp;
kvad = t/g^2; linj = t/g;
disp([x f fp t kvad linj]);
x = x-t;
end
rot = x; disp("Newton")
x = 0;
t = 1;
format short e
disp("x f(x) fprim(x) korr kvad linje")
while abs(t)>8e-8
f = 51.*x-((x.^2+x+0.03)/2.*x+1).^7-17.*x.*exp(-1.*x);
fp = 51 – 7.*((x.^2+x+0.3).^6).*(2.*x.^2+2.*x+0.4)/((2.*x+1).^8)-17.*(exp(-1.*x)-exp(-1.*x));
g=t;
t=f/fp;
kvad = t/g^2; linj = t/g;
disp([x f fp t kvad linj]);
x = x-t;
end
rot = x; finding roots, newtons method, matlab MATLAB Answers — New Questions