Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: ODEs taking variables below 0
Replies: 1   Last Post: Mar 28, 2013 10:05 AM

 Messages: [ Previous | Next ]
 Steven Lord Posts: 18,038 Registered: 12/7/04
Re: ODEs taking variables below 0
Posted: Mar 28, 2013 10:05 AM

"Matthew " <s0700340@sms.ed.ac.uk> wrote in message
news:kj1h3u\$ge\$1@newscl01ah.mathworks.com...
> I have a problem with ODEs taking variables below 0 or some limit. This
> occurs with multiple things like positions, pressures and volumes.
>
> For example, a piston head should stop when it hits the end, say its
> called xend = 1m. z(3) is the position of the piston, while dz(3) is the
> change in position, which is the velocity, va.
>
> I have a piece of code which says that if the piston head is at xend, then
> dz(3) is 0 if its going to push it further past xend. However this code
> doesn't work if say z(3) is at 0.99 and then dz(3) is 0.02, in this case
> it does not register that it will go beyond xend. The code is listed at
> the bottom.
>
> I have tried making statements like the one below but they don't seem to
> work, maybe i have some syntax wrong. The one below is just a simple
> version of what would be required for example.

Either use an Events function or set the ODE option NonNegative using
ODESET.

http://www.mathworks.co.uk/help/matlab/ref/odeset.html

If you're just worried about the ODE solver returning values less than 0,
the NonNegative option will do what you need. If there are events (like the
piston reaching its upper limit, not the lower limit) to which you need to
react use an Events function. For one example of how to use an Events
function, see the example BALLODE.

--
Steve Lord
slord@mathworks.com