Easier ways to write this scipt.

조회 수: 36 (최근 30일)
Kristian Torres
Kristian Torres 2019년 12월 1일
답변: Bhaskar R 2019년 12월 1일
clear;
clc;
balance = 1000;%initial deposit
deposit = 500; %yearly deposit
APR = 0.04; %interest rate
years =[0:14]; %years of deposit
for years = years + 1
years < 15
principal = balance + (balance*APR)
balance =balance +deposit
fprintf ('After %d years the balance in your account will be $%.2f\n',years,balance);
end
fprintf('final balance after %dyears is $%.2f\n',years,balance);
Use a for loop in MATLAB to determine how much money you would have at your bank account in 15 years if you deposit $1000 initially and $500 at the end of each year, assuming the APR is 4%.

답변 (1개)

Bhaskar R
Bhaskar R 2019년 12월 1일
clear;
clc;
balance = 1000;%initial deposit
deposit = 500; %yearly deposit
APR = 0.04; %interest rate
% years =[0:14]; %years of deposit
for years = 0:14
principal = balance + (balance*APR);
balance =balance +deposit;
fprintf ('After %d years the balance in your account will be $%.2f\n',years,balance);
end
fprintf('final balance after %dyears is $%.2f\n',years,balance);

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by