Mathematica NDSolve initial condition

  • Mathematica
  • Thread starter karlzr
  • Start date
  • #1
131
2
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}]
q[0]/.%

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!
 

Answers and Replies

  • #2
42
9
Why can't you drop the terms multiplied by ##10^{-35}## and ##10^{-36}##? I tried doing it, and it works.
 
  • #3
131
2
Why can't you drop the terms multiplied by ##10^{-35}## and ##10^{-36}##? I tried doing it, and it works.
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.
 
  • #4
42
9
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.
 
  • #5
131
2
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!
 
  • #6
30,274
6,736
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.
 
  • #7
131
2
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!
 

Related Threads on Mathematica NDSolve initial condition

Replies
3
Views
4K
Replies
1
Views
1K
  • Last Post
Replies
1
Views
7K
  • Last Post
Replies
3
Views
2K
Replies
8
Views
8K
Replies
2
Views
2K
Replies
3
Views
1K
Replies
4
Views
5K
Replies
8
Views
4K
Top