Inline ; use anonymous functions instead.
5 次查看(过去 30 天)
显示 更早的评论
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
2018-11-21
"what should i do?"
Read the help on anonymous functions, practice a little bit, and then use one in your code.
采纳的回答
madhan ravi
2018-11-21
编辑:madhan ravi
2018-11-21
cf=input('ingrese funcion a evaluar: ','s');
derivada=diff(str2sym(cf),x); %change this line too
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!