1

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?

horchler
  • 3,203
  • It might help to read the manual http://www.mathworks.com/help/symbolic/diff.html?s_tid=gn_loc_drop. – copper.hat Jan 01 '16 at 09:57
  • I read it. But couldn't understand what to do. – Raihan Khalil Jan 01 '16 at 10:03
  • There are some examples there, why not try them? – copper.hat Jan 01 '16 at 19:06
  • 1
    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. – horchler Jan 01 '16 at 22:10

1 Answers1

1
x=sym('x');
func=input('enter function as function of x');
f=inline(func);
fprime=diff(func);