ode45 Two Variable Differential equation Problem - Too many inputs error

14 ビュー (過去 30 日間)
Timothy Morell
Timothy Morell 2020 年 11 月 23 日
コメント済み: Timothy Morell 2020 年 11 月 23 日
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

採用された回答

Stephan
Stephan 2020 年 11 月 23 日
編集済み: Stephan 2020 年 11 月 23 日
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 件のコメント
Timothy Morell
Timothy Morell 2020 年 11 月 23 日
Thank you. My code obviously has other errors but this at least gets the code running. Much appreciated.

サインインしてコメントする。

その他の回答 (0 件)

製品

Community Treasure Hunt

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

Start Hunting!

Translated by