I'm using MATLAB R2013a. I want to input an equation in Matlab, e.g., $f(x) = x^2 - 2 x + 3$. I want it to be inputted by the user. I use the inline function for this:

func = input('Enter a function: ','s');
f = inline(func);

I have been able to do some work with this, but I want to differentiate the equation. I was trying to use the diff function for this, but it doesn't work. Using diff(f,x); results in an error. How can I solve my problem?

  • $\begingroup$ It might help to read the manual mathworks.com/help/symbolic/diff.html?s_tid=gn_loc_drop. $\endgroup$
    – copper.hat
    Jan 1, 2016 at 9:57
  • $\begingroup$ I read it. But couldn't understand what to do. $\endgroup$ Jan 1, 2016 at 10:03
  • $\begingroup$ There are some examples there, why not try them? $\endgroup$
    – copper.hat
    Jan 1, 2016 at 19:06
  • 1
    $\begingroup$ inline is deprecated and shouldn't be used. You can try str2func and/or sym/symfun. Also, consider writing a function with input arguments instead of using input. Finally, if you have an error, it would be helpful to provide it in full (and indicate what you're inputting that causes it so we replicate the issue). This sounds like a programming issue and thus off-topic for this site. You should probably close it and ask an improved version at StackOverflow.com/Matlab. $\endgroup$
    – horchler
    Jan 1, 2016 at 22:10

1 Answer 1

func=input('enter function as function of x');

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .