how to use derivation to a function from the user

5 vues (au cours des 30 derniers jours)
Manal
Manal le 28 Nov 2017
Commenté : Manal le 28 Nov 2017
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 commentaires
Stephen23
Stephen23 le 28 Nov 2017
"I need to do derivation of the entered function"
Do you need a symbolic result or a numeric result?
Manal
Manal le 28 Nov 2017
both I need to display the derivative then the result of x that inputted by the user

Connectez-vous pour commenter.

Réponses (2)

KSSV
KSSV le 28 Nov 2017
syms x
f = sin(x) ;
df=diff(f)
  3 commentaires
KSSV
KSSV le 28 Nov 2017
Did you use syms x ?
Manal
Manal le 28 Nov 2017
yes

Connectez-vous pour commenter.


Jan
Jan le 28 Nov 2017

Community Treasure Hunt

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

Start Hunting!

Translated by