how can a symbolic derivative be vectorized automatically?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
here is the simplified problem.
I have a symblic function with three arguments. And the derivative of f wrt. b
syms a b c
f = a*sin(b)*exp(c)
df = diff(f,b)
The solution is:
df = a*exp(c)*cos(b)
Now i will use this derivatve in a numeric script. And the argumetns a,b,c are vectors:
a=rand(10,1);
b=rand(10,1);
c=rand(10,1);
My current approach is to modify the derivative manualy: (adding "dots")
df = a.*exp(c).*cos(b)
Is there a way how i can change a symblic expression automatically?
My equations are has 80 or more characters and the derivatives has 2x to 3x the amount of characters.
So an automatic transform into an vectorized version would help me a lot.
Best regards,
MJ
0 Commenti
Risposta accettata
Stephen23
il 20 Ott 2023
Use MATLABFUNCTION:
syms a b c
f = a*sin(b)*exp(c)
df = diff(f,b)
mf = matlabFunction(df)
a=rand(10,1);
b=rand(10,1);
c=rand(10,1);
mf(a,b,c)
0 Commenti
Più risposte (2)
Dyuman Joshi
il 20 Ott 2023
Convert it to a function handle -
syms a b c
f = a*sin(b)*exp(c)
df = diff(f,b)
%Convert the symbolic function to an anonymous function
fun = matlabFunction(df)
a=rand(10,1);
b=rand(10,1);
c=rand(10,1);
fun(a,b,c)
0 Commenti
Walter Roberson
il 20 Ott 2023
format long g
syms a b c
f(a,b,c) = a*sin(b)*exp(c)
df = diff(f,b)
A = rand(10,1);
B = rand(10,1);
C = rand(10,1);
D = df(A, B, C)
vpa(D)
double(D)
0 Commenti
Vedere anche
Categorie
Scopri di più su Assumptions 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!