This method uses the same theorem of the Newton-Raphson method to find the x, to understand it better remember the equation of Newton-Raphson to find the x
To understand the multiple root method we can write this equation of the form x = xo- (u),
What the multiple root method does is that it takes the last term and modifies it so that it returns to the original form, that is.
After doing the proper operations, it can be concluded that:
PSEUDOCODE MULTIPLE ROOTS
Read Xo, Tolerance, Iter
I = f (Xo)
Do = f '' (Xo)
D2o = f '' (Xo)
2part = Do ^ 2 - (I * D2o)
Counter = 0
Error = Tolerance + 1
While I ~ = 0 & 2part ~ = 0 & Error> Tolerance & Counter <Iter Do
X1 = Xo - ((Yo * Do) / 2part)
I = f (X1)
Do = f '(X1)
D2o = f '' (X1)
2part = Do ^ 2 - (I * D2o)
Error = abs ((X1 - Xo) / X1)
Xo = X1
Counter = Counter + 1
End While
If I = 0 then
show 'Xo is root'
But If Error <Tolerance then
show 'Xo is an approximate root thanks to tolerance'
End if
End if
End process
CODE
clc %limpia la ventana de comando
clear %Borra todas las variables anteriormente definidas
close all %Cierra todas la ventanas abiertas
format long %Define el formato en long
f = @(x) log((x.^2)+1)+(x.*cos(6.*x+3))-3.*x-10;
df = @(x) ((2.*x)./(x.^2+1))-(6.*x.*sin(6.*x+3))+cos(6.*x+3)-3;
d2f= @(x) [-(4.*x.^2)./(x.^2+1).^2]+[2./(x.^2+1)]-12.*sin(6.*x+3)-36.*x.*cos(6.*x+3);
x0=input('Ingrese x0: ');
Tolerancia=input('Ingrese Tolerancia: ');
N_Iteraciones=input('Ingrese N_Iteraciones: ');
Contador=1;
Error=Tolerancia+1; %Se predefine el error
Den=(((df(x0).^2)-(f(x0)*df(x0)))/(df(x0).^2)); %Se define una variable que posteriormente sera denominador de el punto resultante involucrado en el calculo de la raiz
while Error>Tolerancia && f(x0)~=0 && Contador<N_Iteraciones
x1=x0-((f(x0)/df(x0))/(((df(x0).^2)-(f(x0)*df(x0)))/(df(x0).^2))); %Se define el punto suguiente
Error=abs(x1-x0); %Se predefine el error
%------------------------
T(Contador, 1)=Contador; %|
T(Contador, 2)=x0; %|
T(Contador, 3)=f(x0); %| %Se crea la tabla
T(Contador, 4)=df(x0); %|
T(Contador, 5)=d2f(x0); %|
T(Contador, 6)=Error; %|
%------------------------
x0=x1;
Den=(((df(x0).^2)-(f(x0)*df(x0)))/(df(x0).^2));
Contador=Contador+1;
endwhile
if f(x0)==0 %Se comprueba si el nuevo punto inicial es una raiz
formatSpec = '\nLa raiz es %.15f \n \n';
fprintf(formatSpec,x0)
disp(' %iteraciones Valor inicial f(Valor final) df(Valor final) d2f(Valor final) Error')
disp(T)
fplot(f,[x0-1,x0+1]), grid on
break
else
if Error<Tolerancia %Se determina si el error es tolerable, si se divide por cero y si el número de iteraciones es insuficiente
formatSpec = '\nLa aproximacion de la raiz es %.15f con tolerancia de %.15f \n \n';
fprintf(formatSpec,x1,Tolerancia)
disp(' %iteraciones Valor inicial f(Valor final) df(Valor final) d2f(Valor final) Error')
disp(T)
fplot(f,[x1-1,x1+1]), grid on
break
else
if Den==0 %Se determina si se está dividiendo por cero y si el numero de iteraciones es insuficiente
disp('Se está dividiendo por cero')
else %Se determina que el número de iteraciones es insuficiente
formatSpec = '\nNo se encontro la raiz con %d iteraciones \n \n';
fprintf(formatSpec,N_Iteraciones)
disp(' % iteraciones Valor inicial f(Valor final) df(Valor final) d2f(Valor final) Error')
disp(T)
endif
endif
endif