Solve any function Newton Raphson Method

7 ビュー (過去 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
  1 件のコメント
Ahmet Furkan USLU
Ahmet Furkan USLU 2019 年 11 月 24 日
It is worked .
Thanks a lot ...

サインインしてコメントする。


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 Center および File ExchangeNewton-Raphson Method についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by