Re: problems with DSolve
- To: mathgroup at smc.vnet.net
- Subject: [mg99531] Re: problems with DSolve
- From: szymon.stoma at gmail.com
- Date: Thu, 7 May 2009 06:36:35 -0400 (EDT)
- References: <7247615.1241432020517.JavaMail.root@n11> <gtp1i6$k6f$1@smc.vnet.net>
Thanks a lot for this in-depth answer. It encourage me to go couple of steps further with mathematica to check whether it will be suitable for solving some overparametrized systems describing biological systems (kinetics of gene cascades). i will try to inform people here what was the result (if i would manage to finish). It is interesting, new perspective for me, since previously i was using numerical approach and tools like c/python. thanks for GREAT job. On May 5, 11:40 am, "David Park" <djmp... at comcast.net> wrote: > Let's see what happens when the Plot statement tries to get its first poi= nt, > say at t = 0 (although it probably doesn't actually start there.) Then = you > get > > Plot[(x[0] /. DSolve[{x'[0] == y[0], y'[0] == -x[0], x[0] == = 1, y[0] > == 2}, {x, y}, 0]), at t = 0] > > and your Dsolve equations and statement are shot to pieces because t has > been everywhere replaced by 0. > > Whenever you are plotting it is better to calculate the plotting function= s > FIRST instead of trying to cram all calculations into the plot statement. > > In your example the equations can be solved for the generic case of initi= al > values so: > > Clear[x, y]; sols = > First@DSolve[{x'[t] == y[t], y'[t] == -x[t], x[0] == x0, > y[0] == y0}, {x, y}, t]; > x[x0_, y0_][t_] = x[t] /. sols > y[x0_, y0_][t_] = y[t] /. sols > > Giving > > x0 Cos[t] + y0 Sin[t] > y0 Cos[t] - x0 Sin[t] > > Then, the Manipulate statement would be: > > Manipulate[ > Plot[{x[x0, y0][t], y[x0, y0][t]}, {t, 0, 2 \[Pi]}, > PlotRange -> {{0, 2 \[Pi]}, {-6, 6}}, > Frame -> True], > {{x0, 0}, -5, 5, .1, Appearance -> "Labeled"}, > {{y0, 0}, -5, 5, .1, Appearance -> "Labeled"}] > > In a case like this you should always specify a PlotRange so the scale wo= n't > be jumping around as you vary the conditions, "The Manipulation Jitters". > > If your differential equations are such that you can't obtain a generic > solution with DSolve, but have to use NDSolve on each set of initial > conditions, then you can use the following custom dynamic presentation. A= t > first, it looks more difficult than Manipulate because it is longer. But = it > is actually easier because you have complete control of the layout and th= e > calculation of intermediate results - in this case the solutions to the > differential equations. The main trick here is the use of the second > argument in Dynamic that appears in the controls. For example, the second > argument, (x0 = #; calcsolution[x0, y0]) &, says to set x0 to the curre= nt > value of the slider and then calculate the solutions to the differential > equations using the current values of x0 and y0. > > Module[ > {x0 = -5, y0 = -5, > x, y, calcsolution}, > > (* Routine to calculate the x and y solutions *) > calcsolution[xi_, yi_] := > Module[{sols}, > Clear[x, y]; > sols = First@ > NDSolve[{x'[t] == y[t], y'[t] == -x[t], x[0] == xi= , > y[0] == yi}, {x, y}, {t, 0, 2 \[Pi]}]; > x[t_] = x[t] /. sols; > y[t_] = y[t] /. sols; > ]; > (* Initialize the solutions *) > calcsolution[x0, y0]; > > (* Set up the display and controls *) > Panel[ > Column[ > {(* x0 Slider and InputField *) > Row[{"x0: ", > Slider[Dynamic[x0, (x0 = #; calcsolution[x0, y0]) &], {-5, > 5, .1}], Spacer[10], > InputField[Dynamic[x0, (x0 = #; calcsolution[x0, y0]) &], > FieldSize -> {5, 1}]}], > (* y0 Slider and InputField *) > Row[{"y0: ", > Slider[Dynamic[y0, (y0 = #; calcsolution[x0, y0]) &], {-5, > 5, .1}], Spacer[10], > InputField[Dynamic[y0, (y0 = #; calcsolution[x0, y0]) &], > FieldSize -> {5, 1}]}], > (* Plot *) > Dynamic@ > Plot[{x[t], y[t]}, {t, 0, 2 \[Pi]}, > PlotRange -> {{0, 2 \[Pi]}, {-8, 8}}, > Frame -> True, > ImageSize -> 400] > }](* Column *), > Style["Differential Equations with Dynamic Initial Conditions", 16] > ](* Panel *) > ] > > David Park > djmp... at comcast.nethttp://home.comcast.net/~djmpark/ > > From:szymon.st... at gmail.com [mailto:szymon.st... at gmail.com] > > hello, > > i am new to mathematica, therefore sorry if my question is trivial. I > would like to understand why the following line does not work: > > Plot[(x[t] /. DSolve[{x'[t] == y[t], y'[t] == -x[t], x[0] == = 1, y[0] > == 2}, {x, y}, t]), {t, 0, 5}] > > whereas after splitting into two lines it works: > sol = DSolve[{x'[t] == y[t], y'[t] == -x[t], x[0] == 1, y[0= ] == 2}, > {x, y}, t] > Plot[(x[t] /. sol), {t, 0, 5}] > > i would like to use Manipulate to play with boundary conditions, so > the first notation would be highly useful. > > thanks a lot for any feedback.