Can someone look over my newton's method script and see if it looks ok?
Show older comments
for F(X)=x^3-2x and F'(x)=3x^2-2 with initial guess of x=1
if true
% code
endx = 1;
Tol = 0.0000001;
count = 0;
dx=1;
f=-1;
fprintf('step x dx f(x)\n')
fprintf('---- ----------- --------- ----------\n')
fprintf('%3i %12.8f %12.8f %12.8f\n',count,x,dx,f)
xVec=x;fVec=f;
while (dx > Tol || abs(f)>Tol)
count = count + 1;
fprime = 3*x^2 - 2;
xnew = x - (f/fprime);
dx=abs(x-xnew);
x = xnew;
f = x^3 - 2*x;
fprintf('%3i %12.8f %12.8f %12.8f\n',count,x,dx,f)
end
Accepted Answer
More Answers (0)
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!