A = Table[Sin[2 Pi/ x], {x, 1, 50}];
NDSolve[{y''[x] + Sin[y[x]] y[x] ==
Piecewise[{{Interpolation[A, kkk[x]], z[x] == 1}, {0, True}}],
y[0] == 1, y'[0] == 0, kkk[0] == 100, z[0] == 0,
WhenEvent[x > 9, {z[x] -> 1, kkk[x] -> 1}]}, y, {x, 0, 30},
DiscreteVariables -> {kkk, z}]
By using above code I get this error
InterpolatingFunction::dmval: "Input value {100.} lies outside the range of data in the interpolating function. Extrapolation will be used.
but when I change the WhenEvent
as follow there is no error.
WhenEvent[x > 9, {kkk[x] -> 1, z[x] -> 1}]}
Could anybody explain the reason behind this?
It is a simple example of what I am doing. I need to use Discrete Variables which change inside WhenEvent
as a input of a function in NDSolve
.
x=0
,kkk[x]=100
, however your Interpolation only knows the value of A for x (different x...) up to 50 ,as you define in your Table. Hence, it must extrapolate. $\endgroup$