itial Conditions rev = 0:0.001:4; n1 = -1; w1 = [n1; 0; 0]; g1 = d
I need help coding in MATLAB. I want to create a function where I can input different values of n and e and I would get an output of gamma. Can you help me with that?
% Initial Conditions
rev = 0:0.001:4;
n1 = -1;
w1 = [n1; 0; 0];
g1 = deg2rad(8);
C1 = [cos(g1) -sin(g1) 0;
sin(g1) cos(g1) 0;
0 0 1];
[e1, norm_EP1] = DCMtoEP(C1);
% For n = -1 and e1
% Using ode45 to integrate the KDE and DDE
options = odeset('RelTol',1e-12,'AbsTol',1e-12);
result1 = ode45(@K_DDE, rev, [w1; e1; n1], options);
% Extracting information from the ode45 solver
v1 = result1.x;
w_ode1 = result1.y(1:3, :);
e_ode1 = result1.y(4:7, :);
% Finding C11
C11_1 = 1 - 2*e_ode1(2,:).^2 - 2*e_ode1(3,:).^2;
% Initializing arrays
gamma1 = zeros(1, length(v1));
% Finding the nutation angles
for i = 1:length(v1)
gamma1(i) = acosd(C11_1(i));
end
function dwedt = K_DDE(~, w_en)
% Extracting the initial condtions to a variable
w = w_en(1:3);
e = w_en(4:7);
n = w_en(8);
I = 400;
J = 150;
x = (J/I) - 1;
y = n - 1;
% Kinematic Differential Equations
dedt = zeros(4,1);
dedt(1) = pi*(e(4)*(w(1)-1-y) - e(3)*w(2) + e(2)*w(3));
dedt(2) = pi*(e(3)*(w(1)+1-y) + e(4)*w(2) - e(1)*w(3));
dedt(3) = pi*(-e(2)*(w(1)+1-y) + e(1)*w(2) + e(4)*w(3));
dedt(4) = pi*(-e(1)*(w(1)-1-y) - e(2)*w(2) - e(3)*w(3));
% Dynamical Differential Equations
dwdt = zeros(3,1);
dwdt(1) = 0;
dwdt(2) = -24*pi*(-x)*(e(1)*e(2)+e(3)*e(4))*(e(2)*e(3)-e(1)*e(4)) ...
+ 2*pi*(-x)*w(1)*w(3) - 2*pi*w(3)*y;
dwdt(3) = 12*pi*(-x)*(e(1)*e(2)+e(3)*e(4))*(1-2*e(3)^2-2*e(1)^2) ...
- 2*pi*(-x)*w(1)*w(2) + 2*pi*w(2)*y;
% Combining the w and C into one output matrix
dwedt = [dwdt; dedt; 0];
end
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images