# Differential equation with interpolation

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.

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}];


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}]


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


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}]


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