For Programmers: Free Programming Magazines  


Home > Archive > Matlab > December 2005 > Quick question in Euler's Method









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Quick question in Euler's Method
Ivan

2005-12-18, 9:59 pm

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?
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com