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

Mathematica NDSolve initial condition

  1. Mar 5, 2015 #1
    Hi, I am trying to use NDSolve in Mathematica to solve a set of differential-algebraic equations:
    NDSolve[{-6250 f[t] + 0.025 p[t]^2 f[t] + 0.1 f[t]^3 + 3 q[t] f'[t] +
    f''[t] == 0,
    1.5230870989335428*^-35 p[t]^4 + q'[t] ==
    0, -4.32*^36 q[t]^2 + 10/3 \[Pi]^2 p[t]^4 + 0.0125 p[t]^2 f[t]^2 +
    0.025 (-62500 + f[t]^2)^2 == 0, f[0] == 1, f'[0] == 0,
    q[0] == 6.899183459150538*^-13}, {f, p, q}, {t, 0, tf}]

    After solving the equations, I tried check my solution. I found that q[0]=4.75446*10^-15 rather than the initial value 6.899183459150538*^-13 given in the code.I check q[0] because when I plot my solutions, q[t] is somehow constant at 4.75446*10^-15. So could anyone tell me what is going wrong in my code?
    Thank you so much!
  2. jcsd
  3. Mar 5, 2015 #2
    Why can't you drop the terms multiplied by ##10^{-35}## and ##10^{-36}##? I tried doing it, and it works.
  4. Mar 5, 2015 #3
    Do you mean when you evaluate q[0], it gives you the expected value, the number in the code?
    As to those ugly coefficients in the equations: at first they don't appear in my equations. I mean those coefficients are given in terms of physical constants. In order to find the problem, I replaced those equations with the ones you see. I don't think it matters, since both of them gave me the same result.
  5. Mar 5, 2015 #4
    Often it is not numerically stable to blindly solve equations with coefficients in such a large range. What you have to do first, is to understand which terms you can drop/neglect, for example because they are many orders of magnitude smaller than the others.
  6. Mar 5, 2015 #5
    The coefficients vary by so large scale, but each term in the equations should be of similar scale. I guess I can first try redefining my functions so that the coefficients don't differ so much. Thanks!
  7. Mar 5, 2015 #6


    Staff: Mentor

    The other thing that you can do in Mathematica is to use higher precision numbers for your coefficients or even exact numbers (rationals). However, if those are measured coefficients rather than exact numbers, then treating them as exact numbers is likely to hide problems in your methods.
  8. Mar 16, 2015 #7
    I solved the third equation, the algebraic one, for ##p(t)## in terms of the other two functions and substituted this expression into the first two equations. So I have only two equations left for ##f(t)## and ##q(t)##. The initial conditions seem to be fine. But there is some stiffness problem. I guess it is because ##f(t)## is oscillating too rapidly as expected. So does anyone know how to deal with this kind of stiffness problem?
    Thanks so much!
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: Mathematica NDSolve initial condition
  1. NDSolve in Mathematica (Replies: 3)

  2. Mathematica NDSolve (Replies: 3)

  3. Mathematica NDSolve (Replies: 27)