6
$\begingroup$

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!

$\endgroup$
1
  • 1
    $\begingroup$ Providing an example of what you want may improve this question. $\endgroup$ Jun 25, 2013 at 22:17

1 Answer 1

4
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ nice answer. You can also use InterpolatingFunctionGrid[sol] to extract the grid points. $\endgroup$
    – user21
    Jun 26, 2013 at 6:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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