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

Using the formula, you can calculate compound interest Where: A = amount of mone

ID: 2080021 • Letter: U

Question

Using the formula, you can calculate compound interest

Where:

A = amount of money accumulated after n years, including interest

P = principal amount (the initial amount you borrow or deposit)

r = annual rate of interest (as a decimal)

t = number of years the amount is deposited or borrowed for

n = number of times the interest is compounded per year

In Matlab:

1. Write a function that accepts the starting principal (P), the annual interest rate (r), the number of years

The money is in the bank (t), and the number of times the interest is compounded per year (n). Then

display a table that has the accumulated amount (A) for each year. Use fprintf to format

your table as follows:

Plot the amount vs the time in years. Then run it with the following values:

2. Write a similar function that accepts all values as above, but allows the user to deposit a set amount every year (assume the deposit is one lump sum once per year). Again, display a table with annual values and plot the accumulated amount vs the time in years. Run your function with the following values:

3. Say you want to deposit a certain amount annually into an account that earns interest with a target

amount in mind. Write a function that accepts the initial deposit, amount deposited annually, the interest rate, and the number of times interest is compounded annually, and the target

amount the user is seeking. Return to the user the time (in years) needed to reach the target amount, as

well as, a table with all annual values. Provide the user with a graphical representation of the growth.

Run your function with the following values:

A-P(1 + n)nt A=P1+

Explanation / Answer

(1)

clc; clear all; close all;

P=input('Enter Principal amount : ');

r=input('Enter Annual interest rate: ');

t=input('Enter Number of years: ');

n=input(' Frequency (i.e For quaterly=4, semi-annual=2, annual=1) :');

if (n==1 || n==2 || n==4)

else

n=input(' Frequency (i.e For quaterly=4, semi-annual=2, annual=1) :');

end

fprintf('Year Amount ');

for t1=1:1:t

A=P*(1+r/100)^(n*t);

P=A;

fprintf('%d %f ',t1,A);

end

(2)

clc; clear all; close all;

P=input('Enter Principal amount : ');

r=input('Enter Annual interest rate: ');

t=input('Enter Number of years: ');

n=input(' Frequency (i.e For quaterly=4, semi-annual=2, annual=1) :');

if (n==1 || n==2 || n==4)

else

n=input(' Frequency (i.e For quaterly=4, semi-annual=2, annual=1) :');

end

A1=input('Enter annual deposit:');

fprintf('Year Amount ');

for t1=1:1:t

A=A1+P*(1+r/100)^(n*t);

P=A;

fprintf('%d %f ',t1,A);

end