Can NDSolve be used to add new equations at specific time points?

  • Thread starter Thread starter nofilbarlas
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around the use of NDSolve in Mathematica to manage multiple differential equations that are activated at specific time points. Participants explore how to incorporate new equations into an existing system of ordinary differential equations (ODEs) based on time conditions, particularly focusing on the challenges of setting initial conditions appropriately.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes a scenario where they want to add a second differential equation at a specific time (t = 50) while solving an initial equation.
  • Another participant suggests that initial conditions apply to both equations and can be defined outside of a piecewise function.
  • A different participant shares an attempt using NDSolve with a conditional equation but expresses concern over the initial condition not being met at t = 50.
  • One participant proposes a solution using a unit step function to activate the second equation but is uncertain about its effectiveness.
  • Another participant expresses a desire for the first variable to remain at zero until t = 50, after which a new equation should govern its behavior, hinting at the potential use of EventLocator.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach to implement the desired behavior in NDSolve, with multiple competing views and methods being proposed.

Contextual Notes

Participants highlight challenges related to setting initial conditions correctly when transitioning between equations, as well as the limitations of using piecewise functions in this context.

nofilbarlas
Messages
4
Reaction score
0
Hi guys,
I have a differential equation in NDSolve and for example let's say it is just one equation. Based on some time value, I would like to add another differential equation in the NDSolve function and then the system will solve two ODEs. For example,

y' = 2 with y[0] = 1

Let says I run the code from t = 0 until t = 100. I would like Mathematica to add another differential equation in the NDSolve function as soon as it reachs time, let's say, t = 50. So at t = 50 I would then have

x' = x - y with x[50] = 1

Is there a way to do this in Mathematica? Any help would be appreciated. I was able to setup x' as a piecewise function so that when t >= 50 I can turn on x' = x - y but then the initial conditions will be a problem cause I can't setup initial conditions as a piecewise function. Thanks for your help
 
Physics news on Phys.org
The initial conditions apply to both equations, always. Its just a matter of when they're used. Try putting both conditions in, outside of the piece-wise function definition.
 
I tried this:

s = NDSolve[{m'[t] == If[t >= 50, 0.003, 0], n'[t] == 1, m[0] == 10, n[0] == 19000}, {n, m}, {t, 0, 100}]
Plot[Evaluate[m[t] /. s], {t, 0, 100}, PlotRange -> All]

Only problem is that m[0] should be 0 but m[50] = 100 and I am not sure how to put that in the code. Any suggestions? Thanks
 
Hi,

Would this work:

Code:
mysol = NDSolve[{y'[t] == 2, x'[t] == UnitStep[t - 50] (x[t] - y[t]), 
   y[0] == 1, x[0] == 1}, {y, x}, {t, 0, 100}]

not sure though.
 
Thanks for giving it a shot but still not luck. I want x[t] = 0 until t < 50 and then on t >=50, the x'[t] function should take over with the starting condition x[50] = 1. I think somehow the EventLocator for NDSolve can be used but i just don't know how. Any help would be appreciated.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
Replies
8
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 27 ·
Replies
27
Views
7K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K