Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose that $1000 is deposited into an account that pays 5% interest per year,

ID: 3865077 • Letter: S

Question

Suppose that $1000 is deposited into an account that pays 5% interest per year, at the end of each year, the amount in the account is 1.05 times the amount at the beginning of the year. Write a MATLAB program with a for loop to calculate the amount in the account after 10, 20, and 30 years. Repeat problem 1, assuming that the interest is compounded quarterly; that is, one-fourth of the annual interest (1.25%) is added to the account every three months. Also, repeat the problem with monthly compounding. For the account described in Problem 1, write a MATLAB program with a while loop to determine the number of years required for the amount in the account to reach $5,000.

Explanation / Answer

%matlab code

%problem 1
deposit = 1000;
interest = 0.05;
amount10 = 0;

for i=1:10
amount10 = deposit*(1+interest);
deposit = amount10;
end

fprintf('Amount after 10 years: %0.2f ', amount10);

amount20 = amount10;
for i=10:20
amount20 = deposit*(1+interest);
deposit = amount20;
end

fprintf('Amount after 20 years: %0.2f ', amount20);

amount30 = amount20;
for i=20:30
amount30 = deposit*(1+interest);
deposit = amount30;
end

fprintf('Amount after 30 years: %0.2f ', amount30);
%{
output:
Amount after 10 years: 1628.89
Amount after 20 years: 2785.96
Amount after 30 years: 4764.94
%}


%problem 2
deposit = 1000;
interest = 0.25;
amount10 = 0;

% interest added 3 times a year
for i=1:10
amount10 = deposit*(1+interest);
deposit = amount10;
amount10 = deposit*(1+interest);
deposit = amount10;
amount10 = deposit*(1+interest);
deposit = amount10;
end

fprintf('Amount after 10 years: %0.2f ', amount10);

amount20 = amount10;
for i=10:20
amount20 = deposit*(1+interest);
deposit = amount20;
amount20 = deposit*(1+interest);
deposit = amount20;
amount20 = deposit*(1+interest);
deposit = amount20;
end

fprintf('Amount after 20 years: %0.2f ', amount20);

amount30 = amount20;
for i=20:30
amount30 = deposit*(1+interest);
deposit = amount30;
amount30 = deposit*(1+interest);
deposit = amount30;
amount30 = deposit*(1+interest);
deposit = amount30;
end

fprintf('Amount after 30 years: %0.2f ', amount30);
%{
output:
Amount after 10 years: 807793.57
Amount after 20 years: 1274473528.91
Amount after 30 years: 2010764683385.95
%}


%probelm 3
deposit = 1000;
interest = 0.05;
year = 0;
while true
deposit = deposit*(1+interest);
year = year + 1;
if deposit >= 5000
break
end
end
fprintf('Number of years required to reach $5000: %d ', year);
%output: Number of years required to reach $5000: 33

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote