I need help with my MATLAB code. I wanted to numerically integrate the Modified Rodrigiues Parameters. But there is a singularity and the ode45 shows error. How do I use the event function to stop the integration when there is a singularity.
w0 = [0; 0; 0.3];
MRP0 = [0;
0;
-0.198912367379658];
t = 0:100;
% Integrate the Euler equations using ode45
options = odeset('RelTol',1e-10,'AbsTol',1e-10);
[t, y] = ode45(@KDE_MRP, t, [MRP0; w0], options);
% Extract the Euler parameters and angular velocities
MRP = y(:, 1:3);
w = y(:, 4:6);
function dMRPwdt = KDE_MRP(t,MRPw)
I = [0.3; 0.2; 0.4];
L = [0;0;0];
MRP = MRPw(1:3);
w = MRPw(4:6);
dMRPdt = zeros(3,1);
dwdt = zeros(3,1);
C11 = 1 - dot(MRP,MRP) + 2*MRP(1)^2;
C12 = 2*(MRP(1)*MRP(2) - MRP(3));
C13 = 2*(MRP(1)*MRP(3) + MRP(2));
C21 = 2*(MRP(2)*MRP(1) + MRP(3));
C22 = 1 - dot(MRP,MRP) + 2*MRP(2)^2;
C23 = 2*(MRP(2)*MRP(3) - MRP(1));
C31 = 2*(MRP(3)*MRP(1) - MRP(2));
C32 = 2*(MRP(3)*MRP(2) + MRP(1));
C33 = 1 - dot(MRP,MRP) + 2*MRP(3)^2;
C = [C11 C12 C13;
C21 C22 C23;
C31 C32 C33];
dMRPdt = 0.25 * C * w;
dwdt(1) = (-(I(3) - I(2))*w(2)*w(3) + L(1)) / I(1);
dwdt(2) = (-(I(1) - I(3))*w(3)*w(1) + L(2)) / I(2);
dwdt(3) = (-(I(2) - I(1))*w(1)*w(2) + L(3)) / I(3);
% Combine the time derivatives into a single
dMRPwdt = [dMRPdt; dwdt];
end
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps
- 2arrow_forwardneed matlab codearrow_forwardA Boolean function F (A,B,C) of truth table at below(PLS step by step) 1,Provide the minterm expansion of F . 2,Provide the minterm expansion and the maxterm expansion of F’s complement, respectively. Assume that we don’t care the value of F when ABC=001. i. What is the minterm expansion of F? ii. Choose a proper value for the don’t care term and provide the shortest possible expression of POS (product of sum) for F . (Hint: Minimize the number of maxterms)arrow_forward
- Write a MATLAB function, called fixed_point_iteration that inputs a function, g, an initial guess xo, an error tolerance, tol, and a maximum number of iterations, N , and outputs the fixed point of g, obtained using the fixed point iteration, starting with xo- Your function should have an error defined by E = |x,- Xn-1|, and stop when the error is less than the tolerance, or if the number of iterations exceeds N - whichever happens first. Your function header should look something like: | function [c,n,err] = fixed_point_iteration(g,xe, tol,N)arrow_forwardI need help with a MATLAB problem. The following code uses an ode45 function to integrate the Kinematic Differential Equations. What I want to do is C_ode * transpose(C_ode)? I can't do that because C_ode is composed of multiple 3x3 matrices. The function transpose dosen't support N-D arrays. So, how do I accomplish C_ode * transpose(C_ode)? I tried using CCT = sum(C_ode .* permute(C_ode, [2, 1, 3]), 1); but it gives me 3x1 matrices which is incorrect. C_ode * transpose(C_ode) should give the a 3x3 identity matrix. % Initial Conditionsw = [2;-1;1];T = 30;I = [150; 400; 400];EP = [0;0;0;1];C = eye(3,3);tspan = [0 20]; % Using ode45 to integrate w dotoptions = odeset('RelTol',1e-10,'AbsTol',1e-10);result = ode45(@K_DDE, tspan, [w; C(:)], options); % Extracting information from ode solvert = result.x;w_ode = result.y(1:3,:);C_ode = reshape(result.y(4:end,:), [3,3,length(t)]);CCT = C_ode*transpose(C_ode) function dwCdt = K_DDE(t, w_C) w = w_C(1:3); % corrected indexing for w C =…arrow_forwardPlease answer part b using Mathematica. Display code and output pleasearrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education