obviously, I an not a programmer. I saw this code for newton raphson method (for schoolwork), but when i tried to run it, it said that Ishould use an anonymous functions instead. what should i do?
clear , clc
cf=input('ingrese funcion a evaluar: ');
syms x
f=inline(cf);
derivada=diff(cf,x);
df=inline(derivada);
tol = input('ingrese tolerancia: ');
error = 50;
x=input('ingrese un valor inicial: ');
n =0;
disp(' n xi error')
while (error>tol)
fprintf('\t%i\t%3.5f\t%f\n', n, x, error);
n=n+1;
x=x-f(x)/df(x);
error= abs(f(x));
end

2 件のコメント

Stephen23
Stephen23 2018 年 11 月 21 日
"what should i do?"
Read the help on anonymous functions, practice a little bit, and then use one in your code.
rocheska laconsay
rocheska laconsay 2018 年 11 月 21 日
please help me out here. we do not study programming and out of the blue we need to pass a program

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

 採用された回答

madhan ravi
madhan ravi 2018 年 11 月 21 日
編集済み: madhan ravi 2018 年 11 月 21 日

0 投票

see inline() input should be a string
cf=input('ingrese funcion a evaluar: ','s');
derivada=diff(str2sym(cf),x); %change this line too

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Function Creation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by