Mathematica NDSolve initial condition

In summary, the code is giving an incorrect answer for the coefficient for the term with ##10^{-35}## in it.
  • #1
karlzr
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!
 
Physics news on Phys.org
  • #2
Why can't you drop the terms multiplied by ##10^{-35}## and ##10^{-36}##? I tried doing it, and it works.
 
  • #3
matteo137 said:
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
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
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
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
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!
 

1. What is the purpose of specifying initial conditions in NDSolve?

Initial conditions are necessary for NDSolve to solve a differential equation. They provide a starting point for the numerical integration process and determine the behavior of the solution at the beginning of the domain.

2. How do I specify initial conditions in NDSolve?

Initial conditions can be specified using the option InitialCondition in the NDSolve function. The initial condition should be given as a list of equations or a list of lists for systems of equations.

3. Can I use symbolic expressions as initial conditions in NDSolve?

Yes, you can use symbolic expressions as initial conditions in NDSolve. However, make sure to use NumericQ to evaluate the expressions to numerical values before passing them to NDSolve.

4. What happens if I don't specify initial conditions in NDSolve?

If initial conditions are not specified, NDSolve will try to use default initial conditions. However, this may not always give the desired solution, and it is recommended to specify initial conditions for more accurate results.

5. Can I change the initial conditions during the solution process in NDSolve?

Yes, it is possible to change the initial conditions during the solution process using the WhenEvent option in NDSolve. This allows for more flexibility in solving differential equations with changing conditions.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
140
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
266
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
876
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
Back
Top