itial Conditions rev = 0:0.001:4; n1 = -1; w1 = [n1; 0; 0]; g1 = d

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.5: A Closer Look: Loop Programming Techniques
Problem 12E: (Program) Write a program that tests the effectiveness of the rand() library function. Start by...
icon
Related questions
Question

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

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr