Check for missing argument or incorrect argument data type in call to function 'diff'. How to solve the issue? Please help.

3 次查看(过去 30 天)
a=input('Enter the function in the form of variable x:','s');
x(1)=input('Enter Initial Guess:');
error=input('Enter allowed Error:');
f=inline(a)
syms x;
dif=diff(f);
d=inline(dif);
for i=1:100
x(i+1)=x(i)-((f(x(i))/d(x(i))));
err(i)=abs((x(i+1)-x(i))/x(i));
if err(i)<error
break
end
end
root=x(i)

回答(1 个)

Steven Lord
Steven Lord 2020-9-30
The inline function is not recommended. If you were writing a function to be evaluated in MATLAB, you should create an anonymous function (either by typing it explicitly or using str2func.) But since you want to create a symbolic object use the str2sym function instead.

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by