I need help with my MATLAB code. I am using ode45 to solve my differential equation. But, the size of w_ode is 9x645. Size of t is also 1x645. How is that possible? Shouldn't t be 1x101 and w_ode be 9x101? How do I get the size to be 9x101? I need that size because I am subtract that matrix by another matrix of the same size. I_T = 2; J = 1.5; I = [I_T; I_T; J]; w = [-0.1; 0.3; -1.1]; L = [0;0;0]; t = 0:100; % Using ode45 to integrate w dot options = odeset('RelTol',1e-10,'AbsTol',1e-10); result = ode45(@dwdt_Bframe, t, [w; I; L], options); % Extracting information from ode solver t = result.x w_ode = result.y function dwdt = dwdt_Bframe(t, wIL) w = wIL(1:3); I = wIL(4:6); L = wIL(7:9); % The w dot equations dwdt = zeros(9,1); 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); % Keep the values of I and L constant dwdt(4:6) = 0; dwdt(7:9) = 0; end
I need help with my MATLAB code. I am using ode45 to solve my differential equation. But, the size of w_ode is 9x645. Size of t is also 1x645. How is that possible? Shouldn't t be 1x101 and w_ode be 9x101? How do I get the size to be 9x101? I need that size because I am subtract that matrix by another matrix of the same size.
I_T = 2;
J = 1.5;
I = [I_T; I_T; J];
w = [-0.1; 0.3; -1.1];
L = [0;0;0];
t = 0:100;
% Using ode45 to integrate w dot
options = odeset('RelTol',1e-10,'AbsTol',1e-10);
result = ode45(@dwdt_Bframe, t, [w; I; L], options);
% Extracting information from ode solver
t = result.x
w_ode = result.y
function dwdt = dwdt_Bframe(t, wIL)
w = wIL(1:3);
I = wIL(4:6);
L = wIL(7:9);
% The w dot equations
dwdt = zeros(9,1);
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);
% Keep the values of I and L constant
dwdt(4:6) = 0;
dwdt(7:9) = 0;
end
Step by step
Solved in 4 steps with 3 images