Effacer les filtres
Effacer les filtres

How to fix the must be a column vector error?

6 vues (au cours des 30 derniers jours)
Sneh
Sneh le 6 Avr 2023
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);
Error using odearguments
EULER_EQNS must return a column vector.

Error in ode45 (line 107)
odearguments(odeIsFuncHandle,odeTreatAsMFile, solver_name, ode, tspan, y0, options, varargin);
% 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

Réponses (2)

Matt J
Matt J le 6 Avr 2023
You have not inspected what euler_eqns s returning. If you do, you will see that it is not a column vector.

James Tursa
James Tursa le 6 Avr 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.

Catégories

En savoir plus sur Numerical Integration and Differential Equations dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by