Need to record multiple arrays within a while loop

2 visualizaciones (últimos 30 días)
Brian
Brian el 24 de Abr. de 2024
Respondida: Mathieu NOE el 24 de Abr. de 2024
Ive been stuck on this for a bit now and need help. I want to array all values of owed loan amount on a yearly basis within 20 years. I want to array the amount I would owe each year considering the loan payment increases with each years predicted salary growth(3%). Please help me be able to turn the amount owed, and salary after each loop into a saved array
clear, clc
year=0;
salary=60000;
poverty=19720;
protected=poverty*2.25;
while year<20
owed=(salary-protected)*.083;
salary=(salary*1.03);
totalowe=sum(owed);
totalowem=totalowe/12;
year=year+1;
end
disp(owed)

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 24 de Abr. de 2024
indexing is what you need
clear, clc
year=0;
salary=60000;
poverty=19720;
protected=poverty*2.25;
while year<20
k = year+1;
owed(k)=(salary(k)-protected)*.083;
salary(k+1)=(salary(k)*1.03);
totalowe=sum(owed);
totalowem=totalowe/12;
year=year+1;
end
plot(owed)

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Productos


Versión

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by