# Accounting Compound Interest

Suppose that you deposit \$1000 into an account that pays 5% interest per year. At the end of each year the amount in the account is 1.05times the amount at the beginning of the year. Write a MATLAB program to calculate the amount in the account after 10, 20, 30 years.

Repeat the above problem now assuming that the interest is compounded quarterly; that is one-fourth of the annual interest (1.25%) isadded to the account every three months. Also repeat the problem with monthly compounding interest.

For the account described in the first problem write a program with a while loop to determine the number of years required for the amountto reach \$5000.

Solution

clearall

clc

% First part of the homework

X=1000;%Initial money

K=0;%%Condition for iteration

i=1;%%years

while K==0

X=X*1.05;

if i<=10

X1=X;   %%Money accumulated in 10 year,with interest every year

end

if i>10&&i<=20

X2=X;%%Money accumulated in 20 years, with interest every year

end

if i>20&&i<=30

X3=X;%%Money accumulated in 30 years, with interest every year

end

if i>30

K=1;%%finish the calculation

end

end

%% Second part of the homework

X=1000;%Initial money

K=0;%%Condition for iteration

i=1;%%years

j=3;%%moths

while K==0

X=X*1.25;

if i<=10*12/j

X1=X;   %%Money accumulated in 10 years, with interest every four months

end

if i>10*12/j&&i<=20*12/j

X2=X;%%Money accumulated in 20 years, with interest every four months

end

if i>20*12/j&&i<=30*12/j

X3=X;%%Money accumulated in 30 years, with interest every four months

end

if i>30*12/j

K=1;%%finish the calculation

end

end

%%

X=1000;%Initial money

K=0;%%Condition for iteration

i=1;%%years

j=1;%%moths

while K==0

X=X*1.25;

if i<=10*12/j

X1=X;   %%Money accumulated in 10 years, with interest every month

end

if i>10*12/j&&i<=20*12/j

X2=X;%%Money accumulated in 20 years, with interest every month

end

if i>20*12/j&&i<=30*12/j

X3=X;%%Money accumulated in 30 years, with interest every month

end

if i>30*12/j

K=1;%%finish the calculation

end

end

%% Third part of the howework

X=1000;%Initial money

i=1;%%years

j=4;%%moths

while X<=5000

X=X*1.05;

end

i=i-1 %%numbers of years

HW.m

clear all

clc

% First part of the homework

X=1000;%Initial money

K=0;%%Condition for iteration

i=1;%%years

while K==0

X=X*1.05;

if i<=10

X1=X;   %%Money accumulated in 10 year,with interest every year

end

if i>10&&i<=20

X2=X;%%Money accumulated in 20 years, with interest every year

end

if i>20&&i<=30

X3=X;%%Money accumulated in 30 years, with interest every year

end

if i>30

K=1;%%finish the calculation

end

end

%% Second part of the homework

X=1000;%Initial money

K=0;%%Condition for iteration

i=1;%%years

j=4;%%moths

while K==0

X=X*1.25;

if i<=10*12/j

X1=X;   %%Money accumulated in 10 years, with interest every four months

end

if i>10*12/j&&i<=20*12/j

X2=X;%%Money accumulated in 20 years, with interest every four months

end

if i>20*12/j&&i<=30*12/j

X3=X;%%Money accumulated in 30 years, with interest every four months

end

if i>30*12/j

K=1;%%finish the calculation

end

end

%%

X=1000;%Initial money

K=0;%%Condition for iteration

i=1;%%years

j=1;%%moths

while K==0

X=X*1.25;

if i<=10*12/j

X1=X;   %%Money accumulated in 10 years, with interest every month

end

if i>10*12/j&&i<=20*12/j

X2=X;%%Money accumulated in 20 years, with interest every month

end

if i>20*12/j&&i<=30*12/j

X3=X;%%Money accumulated in 30 years, with interest every month

end

if i>30*12/j

K=1;%%finish the calculation

end

end

%% Third part of the howework

X=1000;%Initial money

i=1;%%years

j=4;%%moths

while X<=5000

X=X*1.05;