matlabodeode45

How may I solve this system of 5 equations using ODE45 (algebraic equations involved)?


I am a seasoned Matlab programmer, yet I don't know how to solve this (seemingly) simple problem. I have a system of 5 equations and 5 unknowns:

system

I know how to solve ODEs using ode45 when there are no algebraic equations involved. In the system above, V (velocity) and C (acceleration) are both constant and known. C is the spacecraft transverse acceleration.

This problem should be solved as follows:

  1. At t=0, we know Theta(0), x(0) and y(0). Remember that V and C are both constant and known.
  2. Given Theta(0) and C/V, we get Theta(t1) integrating the 4th equation. With this new value of Theta, we should be able to compute the new Vx(t1) and Vy(t1), which will give us the new values for x(t1) and y(t2).
  3. Repeat

It's important to solve the problem using Matlab's ODE45, because it will eventually get pretty difficult to solve when I add wind, varying gravity and densities, the spacecraft mass and geometry (and inertias and so on!). So I will get a system of dozens of equations which will all be coupled. If I get to know how to solve this simple problem in Matlab, I will understand how to solve more complex ones in the future.

I've scavenged the internet in order to find some help, but it was in vain. Your help is very much appreciated.


Solution

  • With the corrected system you only have 3 state variables to integrate

    function dotu = f(t,u)
        theta = y(1); 
        dotu = [ C/V, -V*cos(theta), V*sin(theta) ];
    end
    

    and this you can then directly insert into the solver

    [ T,U ] = ode45(f, [t0, tf], [ theta0, x0, y0])
    

    using the appropriate values for the initial condition and the integration end.