Why Does NDSolve in Mathematica Only Work with Machine Real Code?

  • Context: Mathematica 
  • Thread starter Thread starter crazybird
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary

Discussion Overview

The discussion revolves around the use of NDSolve in Mathematica for solving partial differential equations (PDEs), specifically addressing issues related to the handling of complex values and boundary conditions. Participants explore the limitations of the IDA method and suggest alternative approaches to resolve errors encountered during the solution process.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant reports an error message indicating that the IDA method in NDSolve only supports machine real code, questioning the implications for complex values.
  • Another participant suggests that the error may stem from the lack of implementation for complex values in the IDA method and recommends trying different methods like "Adams".
  • A participant notes that despite the documentation stating that NDSolve can handle complex numbers, they are unable to access the suggested method options.
  • One participant shares their experience with the code, noting warnings about insufficient boundary conditions and the presence of differential-algebraic equations, while also observing that including dependent variables in the function specification leads to a successful output.
  • Another participant confirms that the modified approach works but expresses uncertainty about the analytic solution's validity.
  • A different participant critiques the boundary conditions specified in the original code, suggesting that more conditions are necessary for a well-posed problem and provides an example of their own boundary conditions.
  • One participant questions how Mathematica approximates solutions in the absence of complete boundary conditions, raising concerns about the uniqueness of solutions in ill-posed systems.
  • Another participant expresses a practical viewpoint, stating that if a solution can be obtained that seems correct, it suffices for their purposes.

Areas of Agreement / Disagreement

Participants express varying opinions on the handling of complex values in NDSolve, the necessity and sufficiency of boundary conditions, and the implications of Mathematica's default behavior in the absence of complete conditions. No consensus is reached on the best approach to resolve the issues presented.

Contextual Notes

Participants highlight limitations related to the handling of complex values in certain methods, the need for sufficient boundary conditions, and the potential for artificial boundary effects when conditions are lacking. These aspects remain unresolved within the discussion.

crazybird
Messages
16
Reaction score
0
I am solving a PDE using NDSolve. It always give a message like:

"For the method`IDA, only machine real code is available. Unable to continue with complex values or beyond floating-point exceptions."

What does this mean? My code is as following.

NDSolve[{∂t S[z, t] == -I z S[z,t] -I A[z,t], ∂t A[z, t] == -I S[z,t] ,
S[z, 0] == 0, S[0, t] == -I t2 /2, A[z, 0] == 0, A[0, t] == t}, {S,A}, {t, 0, 1}, {z, 0, 1}, MaxSteps -> 10^6 ]

Any suggestions? Please Help!
 
Physics news on Phys.org
This http://reference.wolfram.com/mathematica/tutorial/NDSolveIDAMethod.html indicates that one of the possible methods available for numerical solution of differential equations is the IDA method. Either someone didn't implement handling of PDE with complex values or it is not possible to implement handling of complex values. That is what the error message is telling you.

This http://reference.wolfram.com/mathematica/ref/NDSolve.html (when you click on the orange "More Information" box and scroll down until you find Method) shows you that you can explicitly tell it it what method to use. You might try giving NDSolve an option of Method->"Adams" or one of the other methods and see if one of those will sidestep IDA and happily accept complex values. I don't have your functions so I have not actually tested this.
 
Bill: Those Method options are not available somehow. It is strange--the second link you provided says explicitly that "The differential equations in NDSolve can involve complex numbers. "
BTW, the above is the complete code. No additional functions are used. Although it is not the original equations I wanted to solve. I want to use this simple example to test NDSolve. Yet it doesn't work.
 
When I put in your code:

Code:
NDSolve[{D[S[z, t], t] == -I z S[z, t] - I A[z, t], 
  D[ A[z, t], t] == -I S[z, t], S[z, 0] == 0, S[0, t] == -I t^2/2, 
  A[z, 0] == 0, A[0, t] == t}, {S, A}, {t, 0, 1}, {z, 0, 1}, 
 MaxSteps -> 10^6]
I get
During evaluation of In[8]:= NDSolve::pdord: Some of the functions have zero differential order so the equations will be solved as a system of differential-algebraic equations. >>

During evaluation of In[8]:= NDSolve::bcart: Warning: An insufficient number of boundary conditions have been specified for the direction of independent variable t. Artificial boundary effects may be present in the solution. >>

During evaluation of In[8]:= NDSolve::ivcon: The given initial conditions were not consistent with the differential-algebraic equations. NDSolve will attempt to correct the values. >>

During evaluation of In[8]:= NDSolve::mconly: For the method NDSolve`IDA, only machine real code is available. Unable to continue with complex values or beyond floating-point exceptions. >>

Out[8]= {}

BUT, though it shouldn't matter, if I change {S,A} to {S[z,t],A[z,t]}

Code:
NDSolve[{D[S[z, t], t] == -I z S[z, t] - I A[z, t], 
  D[ A[z, t], t] == -I S[z, t], S[z, 0] == 0, S[0, t] == -I t^2/2, 
  A[z, 0] == 0, A[0, t] == t}, {S[z, t], A[z, t]}, {t, 0, 1}, {z, 0, 
  1}, MaxSteps -> 10^6]

I get
{{S(z,t)->InterpolatingFunction[(0. 1.0. 1.),<>][t,z],A(z,t)->InterpolatingFunction[(0. 1. 0. 1.),<>][t,z]}}

Which I think is what you want, right? For some reason, if you include the dependent variables in the function specification it works, though I thought Mathematica didn't need it.
 
Hepth: Yes it works! That's weird! Though I did not perform an analytic sln to check, but at the plot of the result looks well behaved. Thanks a lot!
 
I don't think that's all quite right. For one thing, use lower-case letters for user-defined variable names. Also, I don't thing you're specifying enough boundary conditions so Mathematica is just inserting artificial ones. The boundary condtionss at the initial t=0 should agree. Also, looks like the solutions are just zero up there.

I would recommend giving boundary conditions on both sides (t=0 and t=1) and an initial conditions a(z,0)=f(z), s(z,0)=g(z). This is how I'd code it. I just inserted some reasonable boundary and initial conditions:

Code:
mysol=NDSolve[{D[s[z, t], t] == (-I)*z*s[z, t] - I*a[z, t], 
   D[a[z, t], t] == (-I)*s[z, t], 
 
   s[z, 0] == z*(z - 1), 
   s[0, t] == (-I)*(t^2/2), 
   s[1, t] == 0, 
   
  a[z, 0] == (-z)*(z - 1), 
  a[0, t] == t, 
  a[1, t] == t^2}, 
  {s, a}, {t, 0, 1}, {z, 0, 1}];

  Plot3D[Re[s[z,t]]/.mysol,{z,0,1},{t,0,1}]
 
Jack: Thanks a lot for the suggestions! About the boundary conditions, I find that if I eliminate S[z, 0] == 0 then Mathematica will work. If I add it, and in addition do as Hepth suggested, it also works. Now in your reply, 6 conditions are specified. Is there any way to justify Mathematica's approximation when there could be a lack of boundary conditions? Because in some cases, it is not possible to know all the boundary conditions.
 
I don't know how Mathematica determines default boundary conditions. However, seems to me if you don't have all the boundary conditions, then the system is ill-posed meaning the solution is not unique. But I'm practical: if you can get it to work to get an answer that you feel is correct then that's good enough for me. :)
 
Jack, thank you for the help and comment!
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 3 ·
Replies
3
Views
6K