newton-raphson please help

3 ビュー (過去 30 日間)
Yusuf
Yusuf 2014 年 1 月 18 日
回答済み: Meysam Mahooti 2019 年 12 月 5 日
i want to find roots of f(x)=x(x-1)e^x by using newton raphson but instead of finding df/dx by using code , i want to use central numerical differentiation which is that f_diff(x)=(f(x+h)-f(x-h))/2*h; and h is any variable but smaller is better such as 10^-6 . and i want write each of them as a function file then call just newton-raphson formule and find root.
please help me

回答 (3 件)

Amit
Amit 2014 年 1 月 18 日
function ra = myfunc(x)
% x the input
F = x*(x-1)*(e^x);
and seperately,
functin dif = mydiff(x,h)
dif = (myfunc(x+h)-myfunc(x-h))/(2*h)
  2 件のコメント
Yusuf
Yusuf 2014 年 1 月 18 日
i tried this code but did not work
in order to find roots of F, i need to use x(k+1)=x(k)-[f(x)/f_diff(x)] , i create another function NR = Newton_Root(x0,h,M) %h is the value that uses in mydiff % M is number of iteration % x0 initial value x=x0 for i=0:M x(i+1)=x(i) x(i+1)=x(i)-[myfunc(x)/mydiff(x)] end end
Amit
Amit 2014 年 1 月 18 日
What error you got?
One thing I see is, while using mydiff, you have just used mydiff(x), however it should be mydiff(x,h)

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


Mischa Kim
Mischa Kim 2014 年 1 月 18 日
Try:
function [x, fx] = my_NR(my_tol, h, x0)
x = x0;
while (abs(f(x)) > my_tol)
dx = f(x)/df(x, h);
x = x - dx;
end
fx = f(x);
end
function f_val = f(x)
f_val = x*(x - 1)*exp(x);
end
function df_val = df(x, h)
df_val = (f(x + h) - f(x - h))/(2*h);
end
  1 件のコメント
lola lola
lola lola 2017 年 4 月 8 日
if to the question: diffresensial (f(x+h)-f(h))/h
if you can help to formula?

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


Meysam Mahooti
Meysam Mahooti 2019 年 12 月 5 日

カテゴリ

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