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

  • Thread starter Thread starter nofilbarlas
  • Start date Start date
AI Thread Summary
The discussion revolves around using NDSolve in Mathematica to solve a system of differential equations where new equations are introduced at specific time points. The user seeks to add a second differential equation when the time reaches t = 50, while maintaining consistent initial conditions for both equations. Several attempts are made to implement this, including using piecewise functions and the UnitStep function, but challenges arise with initial conditions and ensuring correct behavior of the equations over time. Suggestions include using EventLocator to manage transitions between equations, but the user remains uncertain about the implementation. The conversation highlights the complexities of dynamically modifying differential equations in Mathematica.
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
Views
538
Replies
1
Views
2K
Replies
4
Views
3K
Replies
3
Views
5K
Replies
1
Views
3K
Replies
6
Views
2K
Back
Top