how to assign initial values to scalar quantities in simulink function. please help
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
function [P_dot, Q_dot, R_dot, phi_dot, theta_dot, psi_dot] = fcn(P,Q, R,phi, theta, psi, step_force_x, step_force_y, step_force_z)
%% parameters
mass = 5;
x = 0.3; % length
y = 0.2; % width
z = 0.1; % height
rx = 0.1; ry = 0.2; rz = 0.1;
% equations
tow_x = ((ry * step_force_z) - (rz * step_force_y)); % along x-axis
tow_y = ((rz * step_force_x) - (rx * step_force_z)); % along y-axis
tow_z = ((rx * step_force_y) - (ry * step_force_x)); % along z-axis
Jx = (mass / 12) * (y^2 + z^2);
Jy = (mass / 12) * (x^2 + z^2);
Jz = (mass / 12) * (x^2 + y^2);
Jxz = 0;
omega_x = tow_x / Jx; % calculating initial values of angular velocity
omega_y = tow_y / Jy;
omega_z = tow_z / Jz;
% Angular moments
Lx = Jx * omega_x;
Ly = Jy * omega_y;
Lz = Jz * omega_z;
% Calculate gamma
gamma = (Jx * Jz) - (Jxz^2);
% OMEGA_dot
P_dot = ((Jxz*(Jx-Jy+Jz)*P*Q)/gamma) - (((Jz*(Jz-Jy)+Jxz^2)*Q*R)/gamma) + ((Jxz*Lz)/gamma) + (Jz*Lx)/gamma;
Q_dot = ((Jz - Jx)*P*R)/Jy - (Jxz*(P^2 - R^2))/ Jy + (Ly / Jy);
R_dot = ((Jx*(Jx-Jy)+Jxz^2)*(P*Q)/gamma) - (((Jxz*(Jx-Jy+Jz))*P*R)/gamma) + ((Jx*Lz)/gamma) + (Jxz*Lx)/gamma;
%EUL_dot
phi_dot = P + Q * sin(phi) * tan(theta) + R * cos(phi) * tan(theta);
theta_dot = Q * cos(phi) - (R * sin(phi));
psi_dot = Q * sin(phi) / cos(theta) + R * cos(phi) / cos(theta);
end
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Classification Ensembles finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

