I need help with my MATLAB code. I am trying to numerically integrate two sets of equations. I want the ode45 to output a column vector of size (12,1). I am getting an error that says unable to meet integration tolerances without reducing the step size, but my t = 0:30. I am only going from 0 s to 30 s. How can that be too much? Can you see if you can fix it? Please make sure it works.   clc; clear all; Problem 2 % Problem 2 (e) % Initial conditions mu = 398600;            % km^3/s^2 R = 7000;               % km I = [500; 600; 800] * 10^-6;    % kg*km^2 A = [0;0]; % Initial PRP and velocity vectors lambda = [1/sqrt(3); 1/sqrt(3); 1/sqrt(3)]; theta = 3;              % deg w = [0; 0; sqrt(mu/R^3)]; t = 0:30;            % sec % Finding EP EP = PRP2EP(lambda, theta); % Using ode45 to integrate KDE and EOM options = odeset('RelTol',1e-10,'AbsTol',1e-10); [t, y] = ode45(@KDE_C, t, [EP; w; I; A], options);   C11 = y(:,1); C12 = y(:,2); C13 = y(:,3); C21 = y(:,4); C22 = y(:,5); C23 = y(:,6); C31 = y(:,7); C32 = y(:,8); C33 = y(:,9); w2 = y(:,10:12); % Plotting the angular velocities plot(t, w2, '-')   xlabel('Time (sec)')   ylabel('Angular Velocity (rad/s)') legend('w1', 'w2', 'w3') plot(t, C11, t, C22, t, C33, '-')   function EP = PRP2EP(lambda, theta)          % Finding EP from PRP     EP1 = lambda(1)*sind(theta/2);     EP2 = lambda(2)*sind(theta/2);     EP3 = lambda(3)*sind(theta/2);     EP4 = cosd(theta/2);     EP = [EP1; EP2; EP3; EP4]; end   function dCwdt = KDE_C(~,EPwI)     EP = EPwI(1:4);     w = EPwI(5:7);     I = EPwI(8:10);     mu = 398600;            % km^3/s^2     R = 7000;        dwdt = zeros(3,1);     C11 = 1-2*EP(2,1)^2-2*EP(3,1)^2;     C12 = 2*(EP(1,1)*EP(2,1)+EP(3,1)*EP(4,1));     C13 = 2*(EP(1,1)*EP(3,1)-EP(2,1)*EP(4,1));     C21 = 2*(EP(1,1)*EP(2,1)-EP(3,1)*EP(4,1));     C22 = 1-2*EP(1,1)^2-2*EP(3,1)^2;     C23 = 2*(EP(3,1)*EP(2,1)+EP(1,1)*EP(4,1));     C31 = 2*(EP(1,1)*EP(3,1)+EP(2,1)*EP(4,1));     C32 = 2*(EP(3,1)*EP(2,1)-EP(1,1)*EP(4,1));     C33 = 1-2*EP(1,1)^2-2*EP(2,1)^2;     C11_dot = C12*w(3) - C13*w(2);     C12_dot = C13*w(1) - C11*w(3);     C13_dot = C11*w(2) - C12*w(1);     C21_dot = C22*w(3) - C23*w(2);     C22_dot = C23*w(1) - C21*w(3);     C23_dot = C21*w(2) - C22*w(1);     C31_dot = C32*w(3) - C33*w(2);     C32_dot = C33*w(1) - C31*w(3);     C33_dot = C31*w(2) - C32*w(1);          dCdt1 = [C11_dot; C12_dot; C13_dot];     dCdt2 = [C21_dot; C22_dot; C23_dot];     dCdt3 = [C31_dot; C32_dot; C33_dot];     K1 = (I(2) - I(3)) / I(1);     K2 = (I(3) - I(1)) / I(2);     K3 = (I(1) - I(2)) / I(3);     R_mag = 7000;     R1 = R_mag*C11;     R2 = R_mag*C21;     R3 = R_mag*C31;     dwdt(1) = K1*w(2)*w(3) - ((3*(sqrt(mu/R^3))^2*K1*R3*R2)/R_mag^2);     dwdt(2) = K2*w(1)*w(3) - ((3*(sqrt(mu/R^3))^2*K2*R1*R3)/R_mag^2);     dwdt(3) = K3*w(1)*w(2) - ((3*(sqrt(mu/R^3))^2*K3*R2*R1)/R_mag^2);     % Combine the time derivatives into a single vector     dCwdt = zeros(12,1);     dCwdt = [dCdt1; dCdt2; dCdt3; dwdt]; end

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I need help with my MATLAB code. I am trying to numerically integrate two sets of equations. I want the ode45 to output a column vector of size (12,1). I am getting an error that says unable to meet integration tolerances without reducing the step size, but my t = 0:30. I am only going from 0 s to 30 s. How can that be too much? Can you see if you can fix it? Please make sure it works.

 

clc;
clear all;


Problem 2
% Problem 2 (e)

% Initial conditions
mu = 398600;            % km^3/s^2
R = 7000;               % km
I = [500; 600; 800] * 10^-6;    % kg*km^2
A = [0;0];

% Initial PRP and velocity vectors
lambda = [1/sqrt(3); 1/sqrt(3); 1/sqrt(3)];
theta = 3;              % deg
w = [0; 0; sqrt(mu/R^3)];
t = 0:30;            % sec


% Finding EP
EP = PRP2EP(lambda, theta);

% Using ode45 to integrate KDE and EOM
options = odeset('RelTol',1e-10,'AbsTol',1e-10);
[t, y] = ode45(@KDE_C, t, [EP; w; I; A], options);

 

C11 = y(:,1);
C12 = y(:,2);
C13 = y(:,3);
C21 = y(:,4);
C22 = y(:,5);
C23 = y(:,6);
C31 = y(:,7);
C32 = y(:,8);
C33 = y(:,9);
w2 = y(:,10:12);

% Plotting the angular velocities
plot(t, w2, '-')  
xlabel('Time (sec)')  
ylabel('Angular Velocity (rad/s)')
legend('w1', 'w2', 'w3')
plot(t, C11, t, C22, t, C33, '-')  


function EP = PRP2EP(lambda, theta)
    
    % Finding EP from PRP
    EP1 = lambda(1)*sind(theta/2);
    EP2 = lambda(2)*sind(theta/2);
    EP3 = lambda(3)*sind(theta/2);
    EP4 = cosd(theta/2);

    EP = [EP1; EP2; EP3; EP4];
end

 

function dCwdt = KDE_C(~,EPwI)

    EP = EPwI(1:4);
    w = EPwI(5:7);
    I = EPwI(8:10);
    mu = 398600;            % km^3/s^2
    R = 7000;   

    dwdt = zeros(3,1);

    C11 = 1-2*EP(2,1)^2-2*EP(3,1)^2;
    C12 = 2*(EP(1,1)*EP(2,1)+EP(3,1)*EP(4,1));
    C13 = 2*(EP(1,1)*EP(3,1)-EP(2,1)*EP(4,1));
    C21 = 2*(EP(1,1)*EP(2,1)-EP(3,1)*EP(4,1));
    C22 = 1-2*EP(1,1)^2-2*EP(3,1)^2;
    C23 = 2*(EP(3,1)*EP(2,1)+EP(1,1)*EP(4,1));
    C31 = 2*(EP(1,1)*EP(3,1)+EP(2,1)*EP(4,1));
    C32 = 2*(EP(3,1)*EP(2,1)-EP(1,1)*EP(4,1));
    C33 = 1-2*EP(1,1)^2-2*EP(2,1)^2;

    C11_dot = C12*w(3) - C13*w(2);
    C12_dot = C13*w(1) - C11*w(3);
    C13_dot = C11*w(2) - C12*w(1);
    C21_dot = C22*w(3) - C23*w(2);
    C22_dot = C23*w(1) - C21*w(3);
    C23_dot = C21*w(2) - C22*w(1);
    C31_dot = C32*w(3) - C33*w(2);
    C32_dot = C33*w(1) - C31*w(3);
    C33_dot = C31*w(2) - C32*w(1);
    

    dCdt1 = [C11_dot; C12_dot; C13_dot];
    dCdt2 = [C21_dot; C22_dot; C23_dot];
    dCdt3 = [C31_dot; C32_dot; C33_dot];

    K1 = (I(2) - I(3)) / I(1);
    K2 = (I(3) - I(1)) / I(2);
    K3 = (I(1) - I(2)) / I(3);
    R_mag = 7000;
    R1 = R_mag*C11;
    R2 = R_mag*C21;
    R3 = R_mag*C31;
    dwdt(1) = K1*w(2)*w(3) - ((3*(sqrt(mu/R^3))^2*K1*R3*R2)/R_mag^2);
    dwdt(2) = K2*w(1)*w(3) - ((3*(sqrt(mu/R^3))^2*K2*R1*R3)/R_mag^2);
    dwdt(3) = K3*w(1)*w(2) - ((3*(sqrt(mu/R^3))^2*K3*R2*R1)/R_mag^2);


    % Combine the time derivatives into a single vector
    dCwdt = zeros(12,1);
    dCwdt = [dCdt1; dCdt2; dCdt3; dwdt];
end

 

 

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Counting Problems
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education