From: Gareth Russell on 3 Dec 2009 06:16 Hi, Does anyone know how to use NDSolve to create the trajectory of motion of a point following positive gradients on an arbitrary landscape (a ListStreamPlot-like path), but with 'momentum'? The idea is that the trajectory would not terminate on smaller local maxima, depending on the momentum term. I don't know exactly how ListStreamPlot does its thing -- I would guess it interpolates the array of gradient pairs, and then uses NDSolve to find the paths. If so, is there way to modify that basic idea to include a momentum-like term? Or would I need to do a full physics-type model as if I were modelling a ball with mass, gravity, friction, etc.? Thanks, -- Gareth Russell NJIT
From: dh on 4 Dec 2009 04:31 Gareth Russell wrote: > Hi, > > Does anyone know how to use NDSolve to create the trajectory of motion > of a point following positive gradients on an arbitrary landscape (a > ListStreamPlot-like path), but with 'momentum'? The idea is that the > trajectory would not terminate on smaller local maxima, depending on > the momentum term. > > I don't know exactly how ListStreamPlot does its thing -- I would guess > it interpolates the array of gradient pairs, and then uses NDSolve to > find the paths. If so, is there way to modify that basic idea to > include a momentum-like term? Or would I need to do a full physics-type > model as if I were modelling a ball with mass, gravity, friction, etc.? > > Thanks, > Hi Garteh, if I understand correctly, you want something like simulated annealing. Thsi can be donme by: NMinimize[f, vars, Method -> "SimulatedAnnealing"]. On the other hand, if you want the momentum-friction approach, here is an example: Clear[mass, friction, x, y, pos, position, pot, grad]; mass = 1; friction = 0.3; tmax = 10; pot[pos_] := pos.pos; grad[{x_, y_}] = Evaluate[{D[pot[{#1, #2}], #1], D[pot[{#1, #2}], #2]}] & @@ {x, y}; position = pos /. NDSolve[{-grad[pos[t]] - friction (pos'[t].pos'[t]) == pos''[t] mass, pos[0] == {1, 0}, pos'[0] == {0, 1}}, pos, {t, 0, tmax}][[1]] ParametricPlot[position[t], {t, 0, tmax}, AspectRatio -> Automatic, PlotRange -> All] Daniel
From: Gareth Russell on 4 Dec 2009 04:38 Hi, Thanks to the response from "Daniel", I was able to get the answer to my own question, so I'm posting it here. Daniel provided the basic model of motion (F=ma) implemented in NDSolve, with an example on a parametric surface. I figured out how to apply it to to an arbitrary surface that starts life as an array of height values. I may have some of the physics oversimplified, esp. friction, but it's ok, I'm not tring to actually model a ball rolling! Gareth Create an interesting surface, based on something in the help function, plus a bowl shape to help the "ball" stay within the bounds. ifun = ListInterpolation[RandomReal[1, {5,5,5,5}], {{0,1},{0,2},{0,3},{0,4}}]; integ = Integrate[ifun[x1, x2, x3, x4], {x1,0,1},{x4,0,4}]; array=Table[integ,{x2,0,2,0.01},{x3,0,3,0.01}]; bowlArray=Table[{x,y}.{x,y},{x,-1,1,0.01},{y,-1,1,0.006666666}]; smoothSurface=ListInterpolation[array+bowlArray,{{0,2},{0,2}}]; Plot3D[smoothSurface[x,y],{x,0,2},{y,0,2}] Create derivative surfaces in the x and y directions. dX=Derivative[1,0][smoothSurface]; dY=Derivative[0,1][smoothSurface]; Clear some variables and set up constants Clear[mass,friction,x,y,pos,position,pot,grad]; mass=1; friction=0.2; gravity=9.81; A function that returns the gradient at a point by sampling from the two surfaces. This was used in Daniel's original version. grad[{x_,y_}]={dX[x,y],dY[x,y]}; For a moving ball, though, there is a problem in that there should be a maximum acceleration due to gravity even at an infinitely steep gradient. A function that (I think) converts the gradient into a force under the principle that F=m g where g=0.981. grav[{x_,y_}]=gravity*Sin[2*Pi+Map[ArcTan,{dX[x,y],dY[x,y]}]]; A function used to plot the trajectory on the surface. trajectory3D[t_]:=Append[position[t],Apply[smoothSurface,position[t]]] Simulate the dynamics! tmax; position=pos/.NDSolve[{-grav[pos[t]]-pos'[t]*0.5==pos''[t] mass,pos[0]=={1.2,1.7},pos'[0]=={1,0}},pos,{t,0,tmax},MaxSteps->100000][[1]]; Plot trajectory on surface Show[Plot3D[smoothSurface[x,y],{x,0,2},{y,0,2}],ParametricPlot3D[trajectory3D[t],{t,0,tmax},PlotStyle->Thickness[0.003]],ViewPoint->{1.3,-2.4,2}] trajectory3D[tmax] A Manipulate[] function to animate the rolling ball. Manipulate[Show[Plot3D[smoothSurface[x,y],{x,0,2},{y,0,2}],ListPointPlot3D[{trajectory3D[t]+{0,0,0.2}},PlotStyle->PointSize[0.05]],Axes->False,Boxed->False,ViewPoint->{1.3,-2.4,2}],{t,0,tmax}] On 2009-12-03 06:16:16 -0500, Gareth Russell <russell(a)njit.edu> said: > Hi, > > Does anyone know how to use NDSolve to create the trajectory of motion > of a point following positive gradients on an arbitrary landscape (a > ListStreamPlot-like path), but with 'momentum'? The idea is that the > trajectory would not terminate on smaller local maxima, depending on > the momentum term. > > I don't know exactly how ListStreamPlot does its thing -- I would guess > it interpolates the array of gradient pairs, and then uses NDSolve to > find the paths. If so, is there way to modify that basic idea to > include a momentum-like term? Or would I need to do a full physics-type > model as if I were modelling a ball with mass, gravity, friction, etc.? > > Thanks, -- Gareth Russell NJIT
|
Pages: 1 Prev: error message in FindClusters[] of text using Next: Integrating with HypergeometricU |