1
$\begingroup$

If I have a second-order nonlinear differential equation as follow:

sol = NDSolve[{*w''[z] - G[z]*w[z] == 0,  w'[0] == 100, w[L] == 0.001}, w[z], z] 

where:

G[z] is local values change with z or it could be an interpolation. Is there any method to solve the equation if G[z] is considered interpolation.

$\endgroup$
3
$\begingroup$

G[z] is local values change with z or it could be an interpolation Is there any method to solve the equation if G[z] is considered interpolation.

It will be better to give more details and example, so one does not have to guess how things defined.

But interpolation functions works the same way as any other function. So as long as the range of data of your G is within the domain of the ODE it should work as is

ClearAll[z, G, w];
G = Interpolation[{1, 2, 3, 5, 8, 5}];

Mathematica graphics

Notice the domain is from 1 to 6.

L = 6;
sol = NDSolve[{w''[z] - G[z]*w[z] == 0, w'[1] == 100, w[L] == 0.001}, w[z], {z, 1, L}]

Mathematica graphics

Plot[Evaluate[w[z] /. sol], {z, 1, L}]

Mathematica graphics

If you give the domain for ODE outside the interpolation function domain, you'll get warnings from NDSolve but it will still work, but result might not be as accurate

ClearAll[z, G, w];
G = Interpolation[{1, 2, 3, 5, 8, 5}]
L = 10;
sol = NDSolve[{w''[z] - G[z]*w[z] == 0, w'[0] == 100, w[L] == 0.001}, w[z], {z, 0, L}]

Warning

 InterpolatingFunction::dmval: Input value {0.} lies outside the range of 
 data in the  interpolating function. Extrapolation will be used.

Now

Plot[Evaluate[w[z] /. sol], {z, 0, L}]   

Mathematica graphics

$\endgroup$
3
  • 2
    $\begingroup$ @MohammadSAl-tawaha Doesn't Nasser's code work with your G? $\endgroup$ – Michael E2 Feb 4 '20 at 1:54
  • $\begingroup$ @MichaelE2 I am sorry. It works very well $\endgroup$ – Mohammad S Al-tawaha Feb 4 '20 at 12:41
  • $\begingroup$ Thank you so much, Nasser. I appreciate what you have answered $\endgroup$ – Mohammad S Al-tawaha Feb 4 '20 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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