I'm quite new to matlab and im having problems with one of the questions for uni.
Calculate the total amount of an inputted investment after n years of growth where the annual interest rate may change at the start of the year but not during the year the annual interest rates should be inputted into a 1D array. The programme should also draw a graph which shows the amount of the investment at the end of each of the n years.
what i've got so far is
p=input('Give the initial amount invested: £');
n=input('Give the number of years: ');
disp('Give the interest rates on successive lines: ')
for i=1:n
x(i)=input('');
end
y=p*(1+(mean(x))/100)^n
fprintf('The total amount is £%1.2f\n',y)
I also did it as a loop, but didn't know which would be betta for a graph
clear
clc
p=input('Give the initial amount invested: £');
n=input('Give the number of years: ');
disp('Give the interest rates on successive lines: ')
for i=1:n
x(i)=input('');
end
for j=1:n
p1=(p*((x(j)/100)))+p;
p=p1;
end
fprintf('The total amount is £%1.2f\n',p1)
I have no idea how to plot the graph is my formula wrong or am I just missing something. I've been at this for a few days now any help would be appreciated
Emma