Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TimeValue around NDSolve

10 views
Skip to first unread message

Joe

unread,
Aug 18, 2012, 3:44:12 AM8/18/12
to
(* #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
des...@rcn.com
Gaithersburg, MD

Bob Hanlon

unread,
Aug 18, 2012, 8:36:43 PM8/18/12
to
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
0 new messages