Clear Filters
Clear Filters

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

1 view (last 30 days)
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)

Answers (1)

Steven Lord
Steven Lord on 30 Sep 2020
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.

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!