The Math Forum

Search All of the Math Forum:

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

Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   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
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Matthew " <> wrote in message
> 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

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
To contact Technical Support use the Contact Us link on

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.