Evaluating derivative using symbolic toolbox
27 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
WILLIAM WENGER
il 9 Feb 2022
Commentato: WILLIAM WENGER
il 11 Feb 2022
Hello all, I am trying to evaluate a derivative using the symbolic tool box.
I chose a simpler exquation to show, but if I can get this to work my code will work.
Here's the issue:
syms x
f_of_x = x^2 * sin(x)
der = diff(f_of_x)
der_2 = der(2)
As you can see I'm trying to evaluate the function @x = 2; but I'm getting the error "index exceeds number of array elements"
I checked the documentation and I literally abandoned my code, and wrote the example code direct from the documentation, still doesn't work.
0 Commenti
Risposta accettata
Paul
il 10 Feb 2022
Two ways to do this:
syms x
f_of_x = x^2 * sin(x);
der = diff(f_of_x,x) % I like to be explicit on the variable of differentiation
der_2 = subs(der,x,2)
Or
f(x) = x^2 * sin(x);
der(x) = diff(f(x),x)
der_2 = der(2)
2 Commenti
Paul
il 10 Feb 2022
"Thank you! For the second example does that work because of the parenthesis on f(x)?"
Yes. f_of_x and f(x) are different types of objects:
syms x
f_of_x = x^2 * sin(x);
f(x) = x^2 * sin(x);
whos
A symfun works very similarly to a mathemetical function. I think there was a thread here not too long ago that discussed differences between sym and symfun objects, but I can't find it.
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Symbolic Variables, Expressions, Functions, and Settings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!