Message Boards Message Boards

0
|
8270 Views
|
6 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Piecewise, Evaluate, and NDSolve

Posted 11 years ago
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.
POSTED BY: Sasha Kasha
6 Replies
Posted 11 years ago
I cant cause I dont have Mathematica installed on my network computer.
Thanks a lot for your help, it works!
POSTED BY: Sasha Kasha
 
You would probably get better feedback when posting code that can be evaluated instead of a screenshot, but try something like
sS[c_?NumericQ, d_?NumericQ] := First[sumSolution[c, d]];
NDSolve[{x''[t] == sS[x[t], t], x[0] == 0, x'[0] == 0}, x, {t, 0, 100}]
POSTED BY: Ilian Gachevski
Posted 11 years ago
Once again (it's a printscreen)



It's clear that Out[93]-Out[96] are lists.


But Out[97]-[99] are numbers.

Then I need to solve the motion equation where the right side is sumSolution[x,t]. 
Neither method evaluated sumSolution as a number
POSTED BY: Sasha Kasha
Posted 11 years ago
Essentially I need to shift the solution u[x,t] to be equal to 0 if t<time[] and to evolve according to eq1 when t>=time[] with the initial condition of u[x,time[]]=? =(ampl[]/Sqrt[2*Pi]/sigma[])*Exp[-((x-ex[])^2)/2/sigma[]^2]}
POSTED BY: Sasha Kasha
Posted 11 years ago
Sorry, I don't have Mathematica installed on my network computer...It means r[0]= =0, r'[0]= =0; r'' respectively. Corrected the code
POSTED BY: Sasha Kasha
Some of your code might not have transmitted well.  What are "r[0]?0,r'[0]?0"  and "r¢¢"?

POSTED BY: Bruce Miller
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract