Multiple roots formula with Matlab
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
uruc am 24 Okt. 2020
Beantwortet: Duncan Carlsmith am 6 Mär. 2023
f(x)= x^4- 6x^3 + 12x^2 - 10x +3
Starting point x0=0
I need the find these points with the multiple roots formula = fi+1 = fi - (f(xi)*f '(xi)) / ([f '(xi)]^2 - f(xi)* f ''(xi))
Can anyone understand this and help us out, thanks a lot.
Alan Stevens am 24 Okt. 2020
I think your formula shoud be
First define your function and its first two derivatives in Matlab
f = @(x) x.^4- 6*x.^3 + 12*x.^2 - 10*x +3; % function
fp = @(x) ...; % first derivative here
fpp = @(x) ...; % second derivative here
Set an initial guess for x and a tolerance. Initialise an error measure and an iteration number. e.g:
x = 5; %initial guess
tol = 10^-6;
err = 1;
its = 0;
Then use a while loop
while err>tol && its<100
xold = x;
x = ... put your iteration formua here
err = abs(x-xold);
Display your result
Be careful not to use an initial guess that makes fp equal zero, or the routine will fail!
John D'Errico am 25 Okt. 2020
Bearbeitet: John D'Errico am 25 Okt. 2020
A big point of this homework assignment may be to understand what happens near that multiple root.
Thus even if we look at the output of roots, we see three approximate roots at 1, but none seem to nail the root at 1.
>> roots([1 -6 12 -10 3])
2.99999999999999 + 0i
1.00000947488643 + 0i
0.999995262556785 + 8.20550203732316e-06i
0.999995262556785 - 8.20550203732316e-06i
You should see that typically, for a triple root, do not expect accuracty in the root as found to be better than roughly the cube root of eps. For a root r of multiplicity n, the resulting accuracy will typically be nthroot(eps( r ),n).
We can see why there is a problem. Here is your function:
>> fun = @(x) x.^4 - 6*x.^3 + 12*x.^2 - 10*x + 3;
>> fun(1 + [-1e-6 0 eps 1e-6])
-8.88178419700125e-16 0 8.88178419700125e-16 0
As you can see, if we try to evaluate fun at any point in the rough interval [1-1e-6 , 1+1e-6], we always get something as close to zero as MATLAB can resolve. We need to go quite a bit further out before it starts to show a different result than zero.
>> fun(1 + [-1e-4 1e-4])
Next, you need to understand that a numerical rootfinder, once it finds that root around x == 1, need not understand the root is a multiple root. As far is it is concerned, a root is just a root.
Weitere Antworten (2)
uruc am 26 Okt. 2020
Duncan Carlsmith am 6 Mär. 2023
Not likely the point of the exercise but this works:
syms x; solve(x^4- 6*x^3 + 12*x^2 - 10*x +3==0,'ReturnConditions',true)
Find more on Matrix Indexing 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!