How to extract coefficients of custom variables in symbolic expression in MATLAB?
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
FAISAL ALQARNI
el 25 de Jul. de 2023
Comentada: Chunru
el 26 de Jul. de 2023
I want to extract the coefficient of i_B from the attached symbolic experession called omega_B and call it p for example, how to do that?
2 comentarios
Respuesta aceptada
Paul
el 25 de Jul. de 2023
Editada: Paul
el 25 de Jul. de 2023
syms psi phi theta i_B j_B k_B psi_dot phi_dot theta_dot
omega_B = (phi_dot - psi_dot*sin(theta))*i_B + (theta_dot*cos(phi) + psi_dot*cos(theta)*sin(phi))*j_B + (psi_dot*cos(phi)*cos(theta) - theta_dot*sin(phi))*k_B
[c,t] = coeffs(omega_B,i_B)
p = c(t == i_B)
Get all the components simultaneously. Using both output arguments of coeffs forces the first output argument to be in the desired order (at least I think that's how it works)
clear c t
[omega,t] = coeffs(omega_B,[i_B j_B k_B])
p = omega(1); q = omega(2); r = omega(3); % if individual components are needed as individual variables
[p;q;r]
[p,q,r]=struct('omega',num2cell(omega)).omega % one line approach
0 comentarios
Más respuestas (1)
Chunru
el 25 de Jul. de 2023
Editada: Chunru
el 25 de Jul. de 2023
Let iB=1, jB=0 and kB=0. Then compute omegaB.
3 comentarios
Dyuman Joshi
el 25 de Jul. de 2023
Not a function let, but the english word 'let'.
He suggested the exact thing you found out on your own (what you mentioned in a comment above).
Ver también
Categorías
Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!