Re: manipulate, NDSolve, Evaluate

*To*: mathgroup at smc.vnet.net*Subject*: [mg98183] Re: manipulate, NDSolve, Evaluate*From*: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>*Date*: Wed, 1 Apr 2009 05:59:03 -0500 (EST)*References*: <gqkuu9$4ad$1@smc.vnet.net> <gqn8q9$t6g$1@smc.vnet.net>

Hi, Here is my reworked version of your code. I removed your comments and inserted mine indicating the changes. i[t_] := If[t < 10 || t > 60, 0, 1] Plot[i[t], {t, 0, 100}, PlotStyle -> {Red, Thick}] RCSoln1[R_, c_: 1, v0_: 0] = DSolve[{v'[t] == 1/c (i[t] - v[t]/R), v[0] == v0}, v[t], t][[1, 1= , 2]]; (*Removed N, DSolve can do it fine. Picked the v[t] out of the \ solution using Part. Using Set (=) instead of SetDelayed (:=) means \ we don't have to use Evaluate in the Plot command. It's often quicker \ too. *) Plot[RCSoln1[1], {t, 0, 100}, PlotStyle -> {Red, Thick}, MaxRecursion -> 9] (* Now the solution can be used directly. Increased MaxRecursion to \ improve the plotting of the discontinuity *) RCSoln1a[R_, c_, v0_] = DSolve[{v'[t] == 1/c (i[t] - v[t]/R), v[0] == v0}, v[t], t][[1, 1= , 2]]; (* Same as above. Also removed use of default values here. It would \ result in ambiguous calling possibilities: in your definition with \ RCSoln1a[R_: 1,c_,v0_: 0] RCSoln1a[2,3] would have worked, but which \ variable now gets its default value? Is it RCSoln1a[2,3,0] or \ RCSoln1a[1,2,3]? The only unambiguous use of default values would be \ to use them at the end*) Show[ Plot[RCSoln1a[1, 1, 0], {t, 0, 100}, PlotStyle -> {Blue, Thick}, MaxRecursion -> 9], Plot[RCSoln1a[1, 5, 0], {t, 0, 100}, PlotStyle -> {Red, Thick}, MaxRecursion -> 9] ] Manipulate[ Plot[RCSoln1a[R, c, 0], {t, 0, 100}, PlotStyle -> {Blue, Thick}, MaxRecursion -> 9] , {R, 1, 5}, {c, 1, 5}] (* There were so many syntax errors in your version of this line of code that I feel that either you don't have Mathematica 6 or 7, which is required for Manipulate or you have syntax coloring switched off, which you shouldn't do. *) Cheers -- Sjoerd On Mar 31, 11:17 am, pajake <jtre... at ix.netcom.com> wrote: > Here is what I have done so far. > > (* First is an injected current that is applied to the cell*) > i[t_] := If[t < 10 || t > 60, 0, 1] > (* now to plot the above equation *) > Plot[i[t], {t, 0, 100}, PlotStyle -> {Red, Thick}] > (* The equation for an RC circuit. Note the IC, and that c = 1. *) > RCSoln1[R_, c_: 1, v0_: 0] := NDSolve[{v'[t] == 1/c (i[t] - v[t]= /R), > v[0] == v0}, v, {t, 0, 100}] > (* Now plotting the above equation, and assigning R = 1 *) > Plot[Evaluate[v[t] /. {RCSoln1[1]}], {t, 0, 100}, PlotStyle -> {Red, > Thick}] > (* Now let R = 1, and change the value of the capacitance in the plot t= o > see what differences this makes *) > RCSoln1a[R_: 1, c_, v0_: 0] := NDSolve[{v'[t] == 1/c (i[t] - v[t= ]/R), > v[0] == v0}, v, {t, 0, 100}] > p1 = Plot[Evaluate[v[t] /. {RCSoln1a[1]}], {t, 0, 100}, PlotStyle -= > > {Blue, Thick}] > p2 = Plot[Evaluate[v[t] /. {RCSoln1a[5]}], {t, 0, 100}, PlotStyle -= > > {Red, Thick}] > Show[p1, p2] > Now compare the difference in the way the plots look when you change the > R (resistance) vs the c (capacitance). In order for the capacitance to > change like shown. What could cause the changes in the resistance and > the capacitance? > > ? What I would like is: to use Manipulate with a slider to vary "c" and > "R". I tried to use this equation. NDSolve[{v'[t] == 1/(a*c) (i[t]= - > v[t]/(b*R), v[0] == v0}, v, {t, 0, 100}]. I changed the equation b= y > putting (a*c) and (b*R). Then with the plot I thought I could add: > Manipulate[Plot[Evaluate[v[t] /. {RCSoln1a[1]}], {t, 0, 100}, ,{a, 0, > 5}, (b, 0, 5) > PlotStyle -> {Blue, Thick}]] > > It did not work. > > This is just the beginning of the text book that I am writing. Thus I > did not go into the finer details of the soma's wall thickness and how > it changes capacitance. I just wanted to show in a graphic manner what > could happen and illustrate a basic equivalent circuit for a cell > membrane. Later on in the book, I go into more details. > > Can you help me now? > Thanks once again > Prof Jake > > Sjoerd C. de Vries wrote: > > > If you've already done it for a specific wall thickness it should be > > very easy to do the same in a Manipulate for variable thickness > > values. > > > Please post more details if you want more specific assistence. > > > Cheers -- Sjoerd > > > On Mar 28, 12:42 pm, pajake <jtre... at ix.netcom.com> wrote: > > >> I am trying to combine, NDSolve with a ODE then using Plot[evaluate] t= o > >> show the results, and then I would like to take it to the next step an= d > >> use Manipulate. > > >> I am working a cell membranes capacitance based on the wall thickness.= = > > >> I would like the plot to show the the membrane voltage vs time,(I have > >> done this with NDSolve and Plot), but I would like to use a slider tha= t > >> reflects the difference in the cell membranes thickness which affects > >> the capacitance. > >> Is this possible? > >> thanks > >> Prof. Jake

**Re: Palette Tutorial/training help**

**Re: Interpolation -> segfault?**

**Re: Palette Tutorial/training help**

**Re: Interpolation -> segfault?**