Message Boards Message Boards

0
|
6207 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

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

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

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

You can use WhenEvent for things like this:

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

POSTED BY: Sean Clarke
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