Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


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

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: 17,944
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 " <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
To contact Technical Support use the Contact Us link on
http://www.mathworks.com




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

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.