How to fix the must be a column vector error?
조회 수: 6 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Matt J
2023년 4월 6일
You have not inspected what euler_eqns s returning. If you do, you will see that it is not a column vector.
댓글 수: 0
James Tursa
2023년 4월 6일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!