Re: TimeValue around NDSolve
- To: mathgroup at smc.vnet.net
- Subject: [mg127754] Re: TimeValue around NDSolve
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Sat, 18 Aug 2012 20:36:33 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-newout@smc.vnet.net
- Delivered-to: mathgroup-newsend@smc.vnet.net
- References: <20120818074423.BC2F66845@smc.vnet.net>
age = 65; eqn1 = y'[t] == 47/1000*y[t] - 5300; sol1 = y[t] /. NDSolve[{eqn1, y[age] == 100000}, y[t], {t, age, 110}][[1]]; data = Table[{t, sol1}, {t, age, 85}]; Plot[sol1, {t, age, 85}, Epilog -> {Red, AbsolutePointSize[3], Point[data]}] However, this can be soved exactly using DSolve. sol2[t_] = Simplify[y[t] /. DSolve[{eqn1, y[age] == 100000}, y[t], t][[1]]] 100000/47 (53 - 6 E^((47 (-65 + t))/1000)) Plot[sol2[t], {t, age, 85}, Epilog -> {Red, AbsolutePointSize[3], Point[data]}] In TimeValue you have fixed the time value at zero. Note that for TimeValue[s, i, 0] this is independent of the intest rate and as you observed there is no change. TimeValue[s, i, t] (1 + i)^t s TimeValue[s, i, 0] s Presumably you want a time slider in addition to the interest rate slider. Manipulate[sol3[t_] := TimeValue[sol2[t], discountRate/100, t2]; Column[{ Grid[ Partition[ Partition[ Table[{t, NumberForm[sol3[t] // N, {8, 2}]}, {t, age, 85}], 7] // Transpose // Flatten, 6], Frame -> All], Plot[sol3[t], {t, age, 85}, PlotRange -> {75000, 200000}, ImageSize -> 288] }], {t2, 0, 20, 1, Appearance -> {"Labeled"}}, {{discountRate, 1.6, "Discount Rate"}, .8, 3, .1, Appearance -> {"Labeled"}}] Bob Hanlon On Sat, Aug 18, 2012 at 3:44 AM, Joe <design at rcn.com> wrote: > (* #1 This expression works. I am trying to get the Present Value using a variable discountRate for each value in this table. *) > age = 65; > eqn1 = y'[t] == 4.7/100 *y[t] - 5300; > sol1 = y[t] /. NDSolve[{eqn1, y[age] == 100000}, y[t], {t, age, 110}]; > Table[sol1, {t, age, 85}] > > (* #2 This attempt fails *) > Manipulate[ > age = 65; > eqn1 = y'[t] == 4.7/100 *y[t] - 5300; > sol2 = TimeValue[y[t] /. { NDSolve[{eqn1, y[age] == 100000}, y[t], {t, age, 110}]}, discountRate/100, 0]; > Table[sol2, {t, age, 85}], > {{discountRate, 1.6, "Discount Rate"}, .8, 3, .1,Appearance -> {"Labeled", Tiny}} > ] > > (* #3 In the complete applet, this method calculates the PV correctly on opening but does not respond to the discountRate slider and eventually causes an error *) > Manipulate[ > age = 65; > eqn1 = y'[t] == 4.7/100 *y[t] - 5300; > sol2 = y[t] /. NDSolve[{eqn1, y[age] == 100000}, y[t], {t, age, 110}]; > Table[TimeValue[sol2, discountRate/100, 0], {t, age, 85}], > {{discountRate, 1.6, "Discount Rate"}, .8, 3, .1, Appearance -> {"Labeled", Tiny}} > ] > > I hope this is a better description of the problem than I provided several days ago. > > Joe Rimback > design at rcn.com > Gaithersburg, MD >
- References:
- TimeValue around NDSolve
- From: Joe <design@rcn.com>
- TimeValue around NDSolve