ode45 Two Variable Differential equation Problem - Too many inputs error

14 Ansichten (letzte 30 Tage)
I need help with solving this. I am not too savvy with Matlab and was hoping I could get some help on here. Thanks in advance!
%% Initial Conditions:
% Initial Quaternion Elements (t=0):
q0 = [0.57 0.57 0.57]'
q40 = 0.159
% Initial Body Rate:
w0 = [0.1 0.1 0.1]' % rad/s
% Inital State:
state0 = [q0;w0]
% Final time (sec)
tf = 50;
%% Integrate
[t, state] = ode45(@KEQuaternion, [0 tf], state0);
%% Plot
%plot(t, state*180/pi); grid
%xlabel('Time(sec)');
%ylabel('Euler Angles (Deg)');
%hold on; plot(t, 90*ones(size(t)), 'r--');
%legend('\psi','\theta','\phi','singular angle for \theta')
function statedot = KEQuaternion(state)
%% Inputs:
% t :time(sec)
% state :states(rad), 3 by 1 vector
%% Outputs:
% statedot :Time derivate of states (rad/s), 3 by 1 vector
%% Define (or Redefine with current values):
q = [state(1); state(2); state(3)];
w = [state(4); state(5); state(6)];
%% Given:
% Quaternion Feedback Gain Matrices (4 cases):
% Case 1:
K1 = [201 0 0;
0 110 0;
0 0 78];
% 10% inaccurate:
mew = 0.9;
% Rate Gain Matrix:
D = 0.316*[1200 0 0;
0 2200 0;
0 0 3100];
% Asymmetric rigid spacecraft inertia matrix:
J = [1200 100 -200;
100 2200 300;
-200 300 3100];
% Skewed Symmetric Matrix:
OM = [0 -w(3) w(2);
w(3) 0 -w(1);
-w(2) w(1) 0];
u = mew*(-OM*J*w-D*w-K1*q)
q4 = -1/2*w'*q
%% Kinematic Equation for Quaternion
omegadot = OM*w+u;
qdot = 1/2*OM*q + 1/2*q4*w;
statedot = [omegadot;qdot]
end

Akzeptierte Antwort

Stephan
Stephan am 23 Nov. 2020
Bearbeitet: Stephan am 23 Nov. 2020
Fixed the input in your functin. Rising t>7 gives warning, since the problem appears to be stiff:
%% Initial Conditions:
% Initial Quaternion Elements (t=0):
q0 = [0.57 0.57 0.57]';
q40 = 0.159;
% Initial Body Rate:
w0 = [0.1 0.1 0.1]'; % rad/s
% Inital State:
state0 = [q0;w0];
% Final time (sec)
tf = 7;
%% Integrate
[t, state] = ode15s(@KEQuaternion, [0 tf], state0);
% Plot
plot(t, state*180/pi); grid
xlabel('Time(sec)');
ylabel('Euler Angles (Deg)');
hold on; plot(t, 90*ones(size(t)), 'r--');
%legend('\psi','\theta','\phi','singular angle for \theta')
function statedot = KEQuaternion(~,state)
%% Inputs:
% t :time(sec)
% state :states(rad), 3 by 1 vector
%% Outputs:
% statedot :Time derivate of states (rad/s), 3 by 1 vector
%% Define (or Redefine with current values):
q = [state(1); state(2); state(3)];
w = [state(4); state(5); state(6)];
%% Given:
% Quaternion Feedback Gain Matrices (4 cases):
% Case 1:
K1 = [201 0 0;
0 110 0;
0 0 78];
% 10% inaccurate:
mew = 0.9;
% Rate Gain Matrix:
D = 0.316*[1200 0 0;
0 2200 0;
0 0 3100];
% Asymmetric rigid spacecraft inertia matrix:
J = [1200 100 -200;
100 2200 300;
-200 300 3100];
% Skewed Symmetric Matrix:
OM = [0 -w(3) w(2);
w(3) 0 -w(1);
-w(2) w(1) 0];
u = mew*(-OM*J*w-D*w-K1*q);
q4 = -1/2*w'*q;
%% Kinematic Equation for Quaternion
omegadot = OM*w+u;
qdot = 1/2*OM*q + 1/2*q4*w;
statedot = [omegadot;qdot];
end
  1 Kommentar
Timothy Morell
Timothy Morell am 23 Nov. 2020
Thank you. My code obviously has other errors but this at least gets the code running. Much appreciated.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by