Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

1.

fun=input('enter function:');
2. f=inline(fun,'x');
3. x=input('x:');
4. h=0.00001;
5. xp=0;
6. tol=0.00001;
7. fprintf(' i x\n');
8. for i=1:100
fx=feval(f,x);
df=(feval(f,x+h)-feval(f,x))/h;
x=x-fx/df;
fprintf('%2g %7.8f\n',i,x);
if (abs(x-xp)<tol)
break;
end
xp=x;
9. end
10. fprintf('x=%5.5f\n',x)
newtonraphsonmethod
enter function:'x^3-5*x+1'
x:0
i x
1 0.20000000
2 0.20163935
3 0.20163968
x=0.20164

You might also like