Solve any function Newton Raphson Method
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I want to input any function and initial value and find roots, iterations with Newton Raphson method.
Can you help us please?
clc; clear all;
syms x
delta=0.0000001;
epsilon=0.00001;
maxi=20;
x0=input('Enter the initial estimate -> '); % Initial estimate
f=input('f(x):'); %enter any function you want to derive
f1=diff(f); %The Derivative of the Function
for k=1:maxi
a=f1(x0);
if abs(a)<0.00001
disp('turevin değeri sıfıra çok yakın, algoritma durur')
break
end
x1=x0-f(x0)/f1(x0);
hata=abs(x1-x0);
hatatek=2*hata/(abs(x1)+delta);
x0=x1;
y=f(x0);
if(hata<delta)||(hatatek<delta)||(abs(y)<epsilon)
break
end
end
disp('root')
x1;
disp('error')
y;
disp('iteration')
k;
1 comentario
Respuestas (2)
Walter Roberson
el 23 de Nov. de 2019
Change
f=input('f(x):'); %enter any function you want to derive
to
f(x)=input('f(x):'); %enter any function you want to derive
jtt
el 4 de Mzo. de 2022
would it be okay if i ask a copy of this in english?
1 comentario
Walter Roberson
el 4 de Mzo. de 2022
disp('derivative value too close to zero, algorithm stops')
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!