Solve any function Newton Raphson Method

2 views (last 30 days)
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;

Answers (2)

Walter Roberson
Walter Roberson on 23 Nov 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
jtt on 4 Mar 2022
would it be okay if i ask a copy of this in english?

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!