Easier ways to write this scipt.
1 view (last 30 days)
Show older comments
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%.
0 Comments
Answers (1)
Bhaskar R
on 1 Dec 2019
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);
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!