Hi,
I solved an equation and the answer is the list of pieces
For[j=1,j<=3,j++,
{
solution=NDSolve[
{eq1, u[x,0]=? =(ampl[[j]]/Sqrt[2*Pi]/sigma[[j]])*Exp[-((x-ex[[j]])^2)/2/sigma[[j]]^2]} , u, {t,0,100}, {x,-100,100}
],
pieceSolution[a_,b_]=Piecewise[{{0, b<time[[j]]},{Evaluate[u[a,b-time[[j]]]/.solution], b>=time[[j]]}}],
temp[c_,d_]=sumSolution[c,d]+pieceSolution[c,d],
sumSolution[c_,d_]=temp[c,d]
}
]
sumSolution[a,b] (*In*)
(*Out*)({
{\[Piecewise], {
{0, b<1},
{{InterpolatingFunction[{{-100.,100.},{0.,100.}},<>][a,-1+b]}, b>=1},
{0, True}
}}
})+({
{\[Piecewise], {
{0, b<2},
{{InterpolatingFunction[{{-100.,100.},{0.,100.}},<>][a,-2+b]}, b>=2},
{0, True}
}}
})+({
{\[Piecewise], {
{0, b<5},
{{InterpolatingFunction[{{-100.,100.},{0.,100.}},<>][a,-5+b]}, b>=5},
{0, True}
}}
})
I can evaluate an equation in each single point:
(*In*) Evaluate[sumSolution[1,3]][[1]]
(*Out*)0.371703
(*In*)sumSolution[1,4]
(*Out*){0.300161}
But I can't use NDSolve with Evaluate
xSol1=NDSolve[{D[r[v],v,v] = = ?Evaluate[sumSolution[r[v],v]][[1]],r[0]?= =0,r'[0]= =?0},r,{v,0,50}]
NDSolve::ndfdmc: Computed derivatives do not have dimensionality consistent with the initial conditions. ?
NDSolve[{r''[v]?({
{\[Piecewise], {
{0, v<0},
{{InterpolatingFunction[{{-100.,100.},{0.,100.}},<>][r[v],v]}, v>=0},
{0, True}
}}
}),r[0]?= =0,r'[0]= =?0},r,{v,0,50}]
What's the deal and how can I fight it??
If sumSolution is just an InterpolationFunction, not "Piecewise construction" NDSolve works perfectly.