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

  • Thread starter nofilbarlas
  • Start date
In summary, the person wants to add another differential equation to the NDSolve function and then the system will solve two ODEs. They tried to do this by having x[t] = 0 until t = 50 and then on t >= 50, the x'[t] function should take over. However, they are not sure if this will work.
  • #1
nofilbarlas
4
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
  • #2
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.
 
  • #3
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
 
  • #4
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.
 
  • #5
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.
 

1. How do I add new equations in NDSolve?

In order to add new equations in NDSolve, you need to use the Append function and specify the new equation and its initial condition. For a system of equations, you can use the List function to combine multiple equations.

2. What is the syntax for adding new equations in NDSolve?

The syntax for adding new equations in NDSolve is NDSolve[{eq1, eq2, ...}, {var1, var2, ...}, {t, tmin, tmax}], where eq1, eq2, ... are the equations, var1, var2, ... are the variables, and tmin, tmax specify the time interval.

3. Can I add new equations in NDSolve to an existing system of equations?

Yes, you can add new equations to an existing system of equations in NDSolve by using the Append function and specifying the new equation and its initial condition. Make sure to also include the existing equations in the NDSolve function.

4. How do I specify the initial condition for a new equation in NDSolve?

To specify the initial condition for a new equation in NDSolve, you need to use the Append function and include the initial condition after the equation. For example, Append[{eq1, eq2, ...}, {newEq, initialCondition}].

5. Can I add new differential equations in NDSolve?

Yes, you can add new differential equations in NDSolve by using the Append function and specifying the new equation and its initial condition. NDSolve is designed to handle systems of differential equations, so you can add as many as you need.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
120
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
248
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
27
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
5K
  • Programming and Computer Science
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top