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?
inlineis deprecated and shouldn't be used. You can trystr2funcand/orsym/symfun. Also, consider writing a function with input arguments instead of usinginput. 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