how do you user input a equation in matlab ? i used inline function but unable to plot the equation. suppose i want my input equation as x-cos(x). and than plot it. how do i do it? Is the following code correct ?
Show older comments
eq = input('enter the equation in x:','s');
g = inline(eq,'x');
Answers (1)
Star Strider
on 26 Aug 2018
Try this instead:
g = str2func(['@(x)' vectorize(eq)]); % Create The Function As An Anonymous Function
Then call your ‘g’ function as you would call any other function:
f = g(x);
1 Comment
Walter Roberson
on 26 Aug 2018
To emphasize: inline() is considered obsolete and has been recommended against for a decade or so.
Categories
Find more on Function Creation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!