I need my code to output in both numerical form and symbolical form.

1 回表示 (過去 30 日間)
Shiv Karpoor
Shiv Karpoor 2023 年 2 月 27 日
コメント済み: Shiv Karpoor 2023 年 2 月 27 日
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

採用された回答

Dyuman Joshi
Dyuman Joshi 2023 年 2 月 27 日
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))
x_sym = 
y_sym = -mobile*ROT(2,1)
y_sym = 
phi0 = 5*d2r;
theta0 = 10*d2r;
psi0 = -phi0;
%numeric values
x_num = double(subs(x_sym,[phi theta psi], [phi0 theta0 psi0]))
x_num = 0.8285
y_num = double(subs(y_sym,[phi theta psi], [phi0 theta0 psi0]))
y_num = -0.1461

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAssumptions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by