how to use derivation to a function from the user

I have been suggested to use anonymous function for functions from the user and it works, but now I need to do derivation of the entered function I try diff and it's not working
str = input('Please enter the function: ', 's');
f = str2func(['@(x) ',str]);
dydx=diff(f);
r1=dydx(2);
disp(r1);

댓글 수: 2

"I need to do derivation of the entered function"
Do you need a symbolic result or a numeric result?
Manal
Manal 2017년 11월 28일
both I need to display the derivative then the result of x that inputted by the user

댓글을 달려면 로그인하십시오.

답변 (2개)

KSSV
KSSV 2017년 11월 28일
syms x
f = sin(x) ;
df=diff(f)

댓글 수: 3

if I try this it will give me this error
Undefined function 'diff' for input arguments of type 'function_handle'
KSSV
KSSV 2017년 11월 28일
Did you use syms x ?
Manal
Manal 2017년 11월 28일
yes

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

질문:

2017년 11월 28일

댓글:

2017년 11월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by