MATLAB: How to calculate derivative of a string

derivative expressionMATLABsymbolicSymbolic Math Toolbox

dear all
i have a problem with calculating the derivative of a aglebraic expression which is string. how can i use diff to calculate the derivative of expression?
the problem is as below:
eq='x^2+x';
f=str2func(['@(x)',eq]);
g=diff(f);
thanks alot

Best Answer

eq='x^2+x';
f = sym(str2func(['@(x)',eq]));
g = diff(f)
Related Question