How to fix the must be a column vector error?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
The following code gives me an error: euler_eqns must be a column vector. How do I fix this?
% Define the initial conditions
q0 = [0; 0; 0; 1];
w0 = [1; 2; 1];
% Define the time span
tspan = [0 20];
% Integrate the Euler equations using ode45
[t, y] = ode45(@euler_eqns, tspan, q0);
% Extract the Euler parameters and angular velocities
q = y(:, 1:4);
% Calculate the precession, nutation, and spin angles
nutation = acos(1 - 2.*q(:,1).^2 - 2.*q(:,3).^2);
precession = asin((2*(q(:,1).*q(:,2) - q(:,3).*q(:,4)))./(sin(nutation)));
spin = asin((2*(q(:,1).*q(:,2) + q(:,3).*q(:,4)))./(sin(nutation)));
% Convert to degrees
psi = rad2deg(precession);
theta = rad2deg(nutation);
phi = rad2deg(spin);
% Plot the angles over time
plot(t, psi, t, theta, t, phi)
legend('Precession', 'Nutation', 'Spin')
xlabel('Time (s)')
ylabel('Angle (deg)')
function dqdt = euler_eqns(t, q)
% Extract the Euler parameters and angular velocities
w = [1; 2; 1;0];
E = [1 0 0 0; 0 1 0 0; 0 0 1 0; 0 0 0 1];
% Calculate the time derivatives of the Euler parameters
dqdt = 0.5 * w.* E;
end
0 comentarios
Respuestas (2)
Matt J
el 6 de Abr. de 2023
You have not inspected what euler_eqns s returning. If you do, you will see that it is not a column vector.
0 comentarios
James Tursa
el 6 de Abr. de 2023
You should double check your derivative function. Shouldn't the result be a 4-element column vector that is a function of q? Neither of these is true for what you have written. Also, if this is supposed to be a quaternion integration this is not a very good way to do it because ode45( ) will not keep the resulting q normalized. You may want to write your own scheme that can do this.
0 comentarios
Ver también
Categorías
Más información sobre Numerical Integration and Differential Equations 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!