|
| Question: You invest $100 in a saving account paying 6% interest per
year, Let y(t) be the amount in your account after y years. If the
interest is compunded continously, then y(t) solves the ODE initial
value problem
y'=ry, r= 0.06 y=100
compunding interest at a discrete time interval,h, coressponds to a
finite difference method to appromimate the solution to the
ddifferential equation. h is expressed as a fraction of a year.
(1)Euler's method, yearly
(2)Euler's method, monthly
%%Euler's method, yearly
%% Initial condition:
t0=0; y0=100; r=0.06;
t(1)=t0; y(1)=y0; Tmax=10;
%% Step size, number of steps
h=1; N=Tmax/h;
%% Solve, storing the solution in array y(j)
for j=1:N
y(j+1)=y(j) + r*h*fn(t(j),y(j));
t(j+1)=t(j)+h;
end
and for monthly, I just change h=1./12 and r=0.06/12 right?
Is there something wrong with my quation?
|
|