Re: Plot3D with NDSolve

*To*: mathgroup at smc.vnet.net*Subject*: [mg81686] Re: Plot3D with NDSolve*From*: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>*Date*: Mon, 1 Oct 2007 04:54:03 -0400 (EDT)*Organization*: The Open University, Milton Keynes, UK*References*: <fdnlg5$klu$1@smc.vnet.net>

sean_incali wrote: > Hello group, > > Let's say I can solve the following DE that depends on 2 paparmeters a > and b, and plot it accordingly. > > eqn = y'[x] == b/(a y[x]) > par = {a -> 1, b -> 1} > > solution = NDSolve[{eqn /. par, y[0] == 0.1}, y, {x, 0.1, 5}]; > > Plot[y[x] /. solution, {x, 0.1, 5}]; > > Above shows a 2d graph in x and y axes. > > > What I want to do is now use one of the parameter as z axis. > > So I need to solve the DE while varying a from 1 to 5 for instance. > > Then I want to graph the solutions as a 3D object. with x. y and a > axis (where a will be the new z axis.) > > I guess I can use Table to iterate the whole procedure, but I wanted > to see how others would approach it. > > For instance, if I use > > eqn = y'[x] == b/(a y[x]) > par = {b -> 1} > > solution = Table[NDSolve[{eqn /. par, y[0] == 0.1}, y, {x, 0.1, 5}], > {a, 1, 5}]; > > Plot[Evaluate[y[x] /. solution], {x, 0.1, 5}]; > > It will shows all the solutions in one 2D graph. I want to see them in > 3D. > > On the side note.. Why does the Plot require the "Evaluate" in the > second code I posted and not in the first code??? > > If someone can explain that that will be great also. > > Thanks in advance as usual. > > sean > > Since it seems that you are using a version of Mathematica below 6.0, a good way to achieve what you want is to use the *StackGraphics* as in In[1]:= $Version Out[1]= 5.2 for Microsoft Windows (June 20, 2005) In[2]:= Needs["Graphics`Graphics3D`"] eqn=y'[x]\[Equal]b/(a y[x]); par={b\[Rule]1}; solution=Table[NDSolve[{eqn/.par,y[0]\[Equal]0.1},y,{x,0.1,5}],{a,1,5}]; Block[{$DisplayFunction=Identity}, gtab=Table[Plot[Evaluate[y[x]/.solution[[a]]],{x,0.1,5}],{a,1,5}]; ] Show[StackGraphics[gtab]]; HTH, -- Jean-Marc