COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

While loop for ode45 solver

• Email
• Follow

```I have written a program that simulates the trajectory of a probe entering earth's atmosphere. This trajectory is modeled by 6 differential equations. I am using ode45 to solve these equations.

I would the solver to calculate a solution until the probe hits the ground, but the point at which it hits the ground is only know after the solution is displayed. I would like to create some sort of while loop that goes like this:
while altitude >= 0
solve set of equations
end
display solution

The problem is that the time at which the probe hits the ground is only known after the code has ran, so there is no way to know that at 1775 seconds into the simulation, the probe hits the ground. However, a time vector (independent variable) must first be defined before the system can be solved. I don't mind having an excess time vector and then for display purposes (equal size vectors) have the time vector chopped to the same size as the solution vector. The solution is working perfectly fine, but it takes so long for each step that any excess results would save time and eliminate bogus subterranean results. Anyone have any ideas on how this feat could be accomplsihed? Thanks.
```
 0

See related articles to this posting

```Dear Stephen!

> I have written a program that simulates the trajectory of a probe entering earth's atmosphere. This trajectory is modeled by 6 differential equations. I am using ode45 to solve these equations.
>
> I would the solver to calculate a solution until the probe hits the ground, but the point at which it hits the ground is only know after the solution is displayed.

Use the 'Events' property in OPTIONS, as suggested by:
help ode45

Good luck, Jan
```
 0

```"Stephen " <hphilli5@utk.edu> wrote in message
news:hmhs21\$a98\$1@fred.mathworks.com...
>I have written a program that simulates the trajectory of a probe entering
>earth's atmosphere. This trajectory is modeled by 6 differential equations.
>I am using ode45 to solve these equations.
> I would the solver to calculate a solution until the probe hits the
> ground, but the point at which it hits the ground is only know after the
> solution is displayed. I would like to create some sort of while loop that
> goes like this:
>  while altitude >= 0
>     solve set of equations
>  end
>  display solution
>
> The problem is that the time at which the probe hits the ground is only
> known after the code has ran, so there is no way to know that at 1775
> seconds into the simulation, the probe hits the ground. However, a time
> vector (independent variable) must first be defined before the system can
> be solved. I don't mind having an excess time vector and then for display
> purposes (equal size vectors) have the time vector chopped to the same
> size as the solution vector. The solution is working perfectly fine, but
> it takes so long for each step that any excess results would save time and
> eliminate bogus subterranean results. Anyone have any ideas on how this
> feat could be accomplsihed? Thanks.

Look at the BALLODE demo for an example that uses an Events function to

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

```
 0