Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Add new equations in NDSolve

  1. Feb 29, 2012 #1
    Hi guys,
    I have a differential equation in NDSolve and for example lets 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, lets 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 cant setup initial conditions as a piecewise function. Thanks for your help
     
  2. jcsd
  3. Feb 29, 2012 #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.
     
  4. Feb 29, 2012 #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
     
  5. Feb 29, 2012 #4
    Hi,

    Would this work:

    Code (Text):

    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.
     
  6. Feb 29, 2012 #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.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Add new equations in NDSolve
  1. NDSolve in Mathematica (Replies: 3)

  2. Problem with ndsolve (Replies: 2)

  3. Mathematica NDSolve (Replies: 27)

Loading...