Hi Diego,
In your code, you are passing a character array to 'sym', this is not correct. Add the following line after function definition.
fun = evalin(symengine,fun);
Change the defintion of dfun to:
dfun = diff(fun);
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!