Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am trying to solve a system of one-dimensional two-point boundary-value problems with NDSolve. I would like use a fixed mesh (specified by me) in the calculation. Is there a way to do this? The mesh can be uniformly spaced. Thanks!

share|improve this question
1  
Providing an example of what you want may improve this question. –  Sjoerd C. de Vries Jun 25 '13 at 22:17
add comment

1 Answer 1

First the mesh where you want NDSolve to solve the ODE-BVP.

(*Specifyling grid*)
{start, end, dist} = {0, 1, 1/10};
SuppliedMesh = N@Range[start, end, dist]

{0., 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.}

Now lets solve an example system below on the specified grid

(* Solving and saving the grid NDSolve uses *)
{sol, {grid}} = 
Reap[y /. Flatten@
 NDSolve[{y''[t] + y[t]/4 == 8, y[start] == 0, y[end] == 0}, 
  y, {t, start, end}, StartingStepSize ->dist, 
  EvaluationMonitor :> Sow[t],Method -> {"FixedStep", Method -> "ExplicitEuler"}]
];
(* Value of the interpolating function on its underlying mesh*)
Needs["DifferentialEquations`InterpolatingFunctionAnatomy`"];
InterpolatingFunctionValuesOnGrid[sol]

{0., -0.366755, -0.653511, -0.85935, -0.983554, -1.02561, -0.985208, -0.862242, -0.656812, -0.369227, 1.66533*10^-16}

Checking if the mesh matches really the supplied one.

SuppliedMesh === grid === Flatten@InterpolatingFunctionGrid[sol]

True

PS:

Now in place of supplying the mesh to NDSolve better one should try to make NDSolve make/use it in run-time while solving the equation by tuning its stepping algorithm. You will find such trick in NDSolvePlugIns.

BR

share|improve this answer
    
nice answer. You can also use InterpolatingFunctionGrid[sol] to extract the grid points. –  user21 Jun 26 '13 at 6:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.