How to take function as an input and differentiate it( str2func not working) ?

syms x;
y = str2func(input('Enter one variable wquation, e.g @(x)2*x - 3: ', 's'));
disp(diff(y))
In this example I have tried to write a function input from user where the diff function will differentiate the function. But the str2func does not work here. Where us the problem I can not find. Can anyone please help me?
I just want to take input from user a function and differentiate it

 Respuesta aceptada

Use str2sym instead of str2func
syms x;
% y = str2sym(input('Enter one variable wquation, e.g @(x)2*x - 3: ', 's'));
y = str2sym('@(x)2*x - 3')
y = 
disp(diff(y))
2

Más respuestas (0)

Etiquetas

Preguntada:

el 11 de Jun. de 2022

Respondida:

el 11 de Jun. de 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by