I need my code to output in both numerical form and symbolical form.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Shiv Karpoor
il 27 Feb 2023
Commentato: Shiv Karpoor
il 27 Feb 2023
Hello MATLAB Community,
Here is my code:
syms phi theta psi
mobile = 110.75;
d2r = pi/180;
r2d = 180/pi;
phi = 5*d2r;
theta = 10*d2r;
if phi >= 0
psi = -phi ;
elseif phi1 <= 0
psi = -phi ;
end
ROT = [(cos(phi)*cos(psi))-(cos(theta)*sin(phi)*sin(psi)) -(cos(phi)*sin(psi))-(cos(theta)*cos(psi)*sin(phi)) (sin(phi)*sin(theta));...
(cos(psi)*sin(phi))+(cos(phi)*cos(theta)*sin(psi)) (cos(phi)*cos(theta)*cos(psi)-sin(phi)*sin(psi)) -(cos(phi)*sin(theta));...
(sin(theta)*sin(psi)) (cos(psi)*sin(theta)) cos(theta)];
x = (mobile/2)*(ROT(1,1)-ROT(2,2))
y = -mobile*ROT(2,1)
So, when you run this code, you get results of x & y in numerical form.
I want my code to output in two forms numerical and in symbolical (in terms keeping x & y as equations).
I tried some ways to achieve it and after verification I saw that the numerical answer won't match the solutions of the equations generated.
When my x & y are in equation form, I can use these equations for differentiation in the later part of my code.
Can anyone please help me with this,
Thank you,
Shiv
0 Commenti
Risposta accettata
Dyuman Joshi
il 27 Feb 2023
Define and substitute the values after obtaining the required result in symbolic form -
syms phi theta psi
mobile = 110.75;
d2r = pi/180;
r2d = 180/pi;
ROT = [(cos(phi)*cos(psi))-(cos(theta)*sin(phi)*sin(psi)) -(cos(phi)*sin(psi))-(cos(theta)*cos(psi)*sin(phi)) (sin(phi)*sin(theta));...
(cos(psi)*sin(phi))+(cos(phi)*cos(theta)*sin(psi)) (cos(phi)*cos(theta)*cos(psi)-sin(phi)*sin(psi)) -(cos(phi)*sin(theta));...
(sin(theta)*sin(psi)) (cos(psi)*sin(theta)) cos(theta)];
%symbolic expressions
x_sym = (mobile/2)*(ROT(1,1)-ROT(2,2))
y_sym = -mobile*ROT(2,1)
phi0 = 5*d2r;
theta0 = 10*d2r;
psi0 = -phi0;
%numeric values
x_num = double(subs(x_sym,[phi theta psi], [phi0 theta0 psi0]))
y_num = double(subs(y_sym,[phi theta psi], [phi0 theta0 psi0]))
Più risposte (0)
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!