Solve any function Newton Raphson Method

조회 수: 8 (최근 30일)
Ahmet Furkan USLU
Ahmet Furkan USLU 2019년 11월 23일
댓글: Walter Roberson 2022년 3월 4일
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
Mariusz
Mariusz 2019년 11월 23일
Hello,
Where Is the problem?
Best

댓글을 달려면 로그인하십시오.

답변 (2개)

Walter Roberson
Walter Roberson 2019년 11월 23일
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 2022년 3월 4일
would it be okay if i ask a copy of this in english?
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 3월 4일
disp('derivative value too close to zero, algorithm stops')

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Newton-Raphson Method에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by