Re: Using manipulate in two cells in one note book crashes my computer.
- To: mathgroup at smc.vnet.net
- Subject: [mg98170] Re: [mg98137] Using manipulate in two cells in one note book crashes my computer.
- From: John Fultz <jfultz at wolfram.com>
- Date: Wed, 1 Apr 2009 05:56:37 -0500 (EST)
- Reply-to: jfultz at wolfram.com
The fact that you're using the variable 'dsol' in both outputs is what's causing the problem. Each time 'dsol' changes, Mathematica wants to update the output. Here's a very simple example of what's going on... Manipulate[n x, {n, 1, 2}] Now, in a separate cell, evaluate 'x=5'. Note that it updates. Set x to something else and it updates again. Now try... Manipulate[x = n, {n, 0, 10}] and drag the slider. Note that it's updating the first Manipulate as well. What you've done is exactly the same, except that each Manipulate triggers the other, causing it to pound the kernel for updated evaluations. It shouldn't be crashing, but the repeated evaluation behavior is the designed behavior. So, you need to either localize 'dsol' (using, e.g., Module, DynamicModule, With), use two different variable names, or not use a variable at all. Now, it turns out that in your case, you could actually save quite a bit of computation here because there's no reason for the DSolve[] to be performed again and again every time you drag your sliders. The output is the same throughout your selected constant ranges. So you could both localize dsol and make your Manipulates more efficient by doing the following... With[{dsol = DSolve[{b''[t] == -k1 k2 b[t] - k1 b'[t], b[0] == b0, b'[0] == bp0}, b[t], t]}, Manipulate[ Plot[Evaluate[b[t] /. dsol], {t, 0, 10}, PlotRange -> All], {k1, 0.1, 10}, {k2, 0.1, 10}, {b0, 0.1, 10}, {bp0, 0.1, 10}]] With[{dsol = DSolve[{k1 k2 b[t] == k1 b'[t] + b''[t], b[0] == b0, b'[0] == bp0}, b[t], t]}, Manipulate[ Plot[Evaluate[b[t] /. dsol], {t, 0, 10}, PlotRange -> All], {k1, 0.1, 10}, {k2, 0.1, 10}, {b0, 0.1, 10}, {bp0, 0.1, 10}]] Sincerely, John Fultz jfultz at wolfram.com User Interface Group Wolfram Research, Inc. On Tue, 31 Mar 2009 04:18:05 -0500 (EST), sean_incali at yahoo.com wrote: > Hello Group. > > I'm having an awful time with this. I have 2 essentially same codes > using manipulate. Only differences are the ODEs. > > When I have both of the cells open, the Mathematica goes crazy, with > the cell brackets flashing as if it's evaluating both cells at the > same time. Eventually it will crash or I have to stop it using "Alt > +." > > Is anyone else having the same problem? > > Here're the cells causing problems. > > cell 1 > > Manipulate[dsol=DSolve[{b''[t]==-k1 k2 b[t]-k1 b'[t], b[0]==b0, b'[0] > ==bp0}, b[t], t]; > Plot[Evaluate[b[t]/.dsol],{t, 0, 10},PlotRange-> All], {k1, 0.1, 10}, > {k2, 0.1, 10}, {b0, 0.1, 10}, {bp0, 0.1, 10}] > > cell 2 > > Manipulate[dsol=DSolve[{k1 k2 b[t]==k1 b'[t]+b''[t], b[0]==b0, b'[0] > ==bp0}, b[t], t]; > Plot[Evaluate[b[t]/.dsol],{t, 0, 10},PlotRange-> All], {k1, 0.1, 10}, > {k2, 0.1, 10}, {b0, 0.1, 10}, {bp0, 0.1, 10}] > > > In two separate notebooks, these two cells cause no problems. In the > same notebook, if one of the cells are closed (by double clicking on > the cell bracket), they don't cause problems. It's only when the cells > are both open, the mathematica goes crazy and crashes. > > > Thanks for any info. > > Sean