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

 채택된 답변

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

추가 답변 (0개)

태그

질문:

2022년 6월 11일

답변:

2022년 6월 11일

Community Treasure Hunt

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

Start Hunting!

Translated by