I need help please !! Newton method
Show older comments
Hi , I know there's a lot of subjects on this but I didn't find what I'm looking for... This is my problem: I have create this code and it works perfectly well :
fonc=inline('fonction');
dfonc=inline('derivée de la fonction');
x=0.8;
;xn=0;
eps=1e-6;
k=0;
fprintf(' k x_k f(x_k) \n');
fprintf('%4d %12.4e %12.4e \n',k, x,fonc(x));
k=k+1;
while abs(x-xn) > eps & k < 20
xn=x;
x=x-fonc(x)/dfonc(x);
fprintf('%4d %12.4e %12.4e \n',k, x,fonc(x));
k=k+1;
end
In this case fonction = x^4-1.3*x^3-2.97*x^2+5.929*x-2.662 and dérivée de la fonction is 4*x^3-3.9*x^2-5.94*x+5.929
k x_k f(x_k)
0 8.0000e-01 -7.5600e-02
1 9.0370e-01 -2.1963e-02
2 9.7064e-01 -6.4300e-03
3 1.0144e+00 -1.8908e-03
4 1.0432e+00 -5.5753e-04
5 1.0623e+00 -1.6467e-04
6 1.0749e+00 -4.8691e-05
7 1.0833e+00 -1.4407e-05
8 1.0889e+00 -4.2649e-06
9 1.0926e+00 -1.2629e-06
10 1.0951e+00 -3.7405e-07
...
29 1.1000e+00 0.0000e+00
My problem is that I have to add a new thing to the table that would be create by this fonction:
abs((xn2-xn)/(xn-x))
and I don't know how to do it... I really need help. It should be looking like this
k x_k f(x_k) |En+1/En|
0 8.0000e-01 -7.5600e-02 0,645515911
1 9.0370e-01 -2.1963e-02 0,653719749
2 9.7064e-01 -6.4300e-03 0,658135283
3 1.0144e+00 -1.8908e-03 0,663194444
4 1.0432e+00 -5.5753e-04 0,659685864
5 1.0623e+00 -1.6467e-04 ...
6 1.0749e+00 -4.8691e-05 ...
7 1.0833e+00 -1.4407e-05 ...
8 1.0889e+00 -4.2649e-06 ...
9 1.0926e+00 -1.2629e-06 ...
10 1.0951e+00 -3.7405e-07 ...
11 1.0967e+00 -1.1080e-07 …
Thank you. ( by the way , english is not my native language so I'm sorry for all the mistakes I may have made. )
2 Comments
Geoff Hayes
on 11 Apr 2015
Thierry - in your equation
abs((xn2-xn)/(xn-x))
does xn2 really mean xn^2 or does it mean something else?
Thierry Gelinas
on 11 Apr 2015
Edited: Thierry Gelinas
on 11 Apr 2015
Accepted Answer
More Answers (0)
Categories
Find more on Linear Algebra 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!