I am learning to use Matlab's ode45 to solve this equation and plot its time history:
$$I_gd\omega/dt + \omega \times (I_g\omega) = 0$$
It was suggested that I use:
omega_dot = fun(t,omega) ...
global I_G
I_G = I_g(:,:,m);
a = I_G*omega;
b = cross(omega,a);
omega_dot = -I_G/b;
I_g is a 3-by-3 inertia matrix predefined in another piece of code. My time vector is tspan = [0 100]. The initial state vector is omega = [1 0 0].
I understand that I need to set up my code in the form:
[t,y] = ode45(@vdpl,[0 20],[2 0]);
plot (t,y(:,1));
I need suggestions on how to make the information that I have work with the information that the examples for ode45 suggest. Any help would be greatly appreciated.
You're nearly there. First, don't use global variables. There's no need. And they're inefficient. The code below shows how to pass in parameters such as your
I_Gmatrix (note thatintegrationfunnow has a third input argument). Second, you didn't definem– it can be passed in just likeI_Gif it's constant (though then it'd make more sense to just pass inI_g(:,:,m)) or you can define it in your integration function. You can define one main function with a sub-function that describes the ODE:By the way, I'm not sure the last line of your integration function matches up with the differential equation you specified.