I need to make a function for compound interest using for
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Matthew
el 19 de Abr. de 2024
Respondida: Dyuman Joshi
el 19 de Abr. de 2024
I am trying to form a conditional loop to show the growth of money, I put in $1000 and want it to grow by 8% every year for 8 years, but I keep returning the same values.
money=1000;
x=zeros(1,10);
for i=1:10
x(i)=money*1.08
end
0 comentarios
Respuesta aceptada
Dyuman Joshi
el 19 de Abr. de 2024
In case you want the final output -
format shortg
money=1000;
for k=1:10
money=money*1.08;
end
money
In case you want the output for each year -
n = 10;
money = 1000*ones(1,n+1);
for k=1:n
money(k+1) = money(k)*1.08;
end
disp(money)
0 comentarios
Más respuestas (1)
Voss
el 19 de Abr. de 2024
Editada: Voss
el 19 de Abr. de 2024
money=1000;
x=zeros(1,8); % x is the balance each year for 8 years
x(1) = money; % initially (1st year) x is 1000
for i=2:numel(x) % loop over years 2 through the end
x(i)=x(i-1)*1.08 % each year's balance is 8% more than the previous year's
end
0 comentarios
Ver también
Categorías
Más información sobre Install Products en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!