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 ?

Answers (1)

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

To emphasize: inline() is considered obsolete and has been recommended against for a decade or so.

Sign in to comment.

Categories

Find more on Function Creation in Help Center and File Exchange

Products

Release

R2016a

Tags

Asked:

on 26 Aug 2018

Commented:

on 26 Aug 2018

Community Treasure Hunt

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

Start Hunting!