Jose Lopez Garcia
Jose Lopez Garcia

Reputation: 982

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.

Upvotes: 0

Views: 640

Answers (2)

Lutz Lehmann
Lutz Lehmann

Reputation: 25972

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.

Upvotes: 1

user3646557
user3646557

Reputation: 309

It seems to me that your system is underdetermined in the sense that y_1 is not constrained by your equations other than it has to be positive. As for the rest of the system, it actually decouples. Here's how I would do it:

1) The first equation implies that y_1 is positive. With that in mind, if you substitute y_2 and y_3 in the first equation you obtain the identity y_1=y_1. So that this point y_1 can be any function of time, subject only to the constraint that at t=0 it satisfies the initial condition. In the following, I will assume it to be a constant in time.

2) With that stipulation, C/y_1 is an arbitrary constant, let's call it B, from which it follows that y_4= Bt + y0_4, y0_4 being the integration constant.

3) Substitute y_2 into the 5th equation and y_3 into the 6th. Now you have two ODEs with a time dependent r.h.s. The equations are simple enough that they can solved analytically. For example, the last equation gives y_6=-y_1/B cos(Bt+y0_4)+y0_6.

More generally, suppose that you had a problem that was not underconstrained. Then, you can always differentiate in time the algebraic equations and obtained a coupled system of ODE.

As a last comment, I would say that, before rushing to Matlab (or Python, or R, or C++,...) it is always a good thing to work on the problem with paper and pencil to see if it can be simplified, or, as is the case above, it can be solved.

Upvotes: 0

Related Questions