Message Boards Message Boards

0
|
6309 Views
|
4 Replies
|
1 Total Likes
View groups...
Share
Share this post:
GROUPS:

How to add constraints on states in ODE's using NDSolve?

Hi, Simplifying my question is that assume an ODE such as

x'[t] = Sin[x[t]]

constrained to:

x[t] = Max[x[t],0.5]

How can I implement this constraint and solve the ODE using NDSolve? Thanks.

4 Replies

You can use WhenEvent for things like this:

http://reference.wolfram.com/language/ref/WhenEvent.html

POSTED BY: Sean Clarke

Thanks, that's exactly what I was looking for.

ok, now I am confused.. going back to my example, lets assume this problem: we have a simple x' = sin(2.pi.t) and we want to make sure that x[t] values do not exceed 0.1 (i.e., trimmed at 0.1). The following script does not work, any idea?

NDSolve[{x'[t] == Sin[2*Pi*t], x[0] == 0, WhenEvent[x[t] > 0.1, x[t] -> 0.1]}, x, {t, 0, 1}];
Plot[x[t] /. %, {t, 0, 1}, AspectRatio -> Automatic]

Plot

Found the answer. I will use Piecewise function in the definition of the derivative.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract