Write a function called retirementAccount that has 4 parameters: initialDepositA
ID: 3764043 • Letter: W
Question
Write a function called retirementAccount that has 4 parameters: initialDepositAmount, mterestRate. niitialWithdrawAmoiuit. inflationRate. The function displays a bar graph of years vs. a vector of [accountBalance' withdrawals']. For example: A person entering retirement is depositing $3 00.000 in a savings account that pays 5% interest per year (paid at the start of each year, starting year 2). The person plans to withdraw money from the account after the interest is applied at the start of each year, starting year 2. He starts by withdrawing $25,000 at the start of the 2nd year, and in future year he increases the amount he withdraws according to the inflation rate. For example, if the inflation rate is 3%. he withdraws $25,750 at the start of the 3rd year.Explanation / Answer
Here you go :
function [years] = retirementAccount(initialDepositAmount, interestRate, initialWithdrawAmount, inflationRate);
% Matlab implementation of velocity function
%
%
% input: initialDepositAmount : initial Deposit Amount
% interestRate : interest Rate
% initialWithdrawAmount : initial Withdraw Amount
% inflationRate : inflation Rate
%
%
% output: years : years
%
%
years = 1;
withdrawalAmount = initialWithdrawAmount;
totalAmount = initialDepositAmount;
figure;
hold on;
y = [totalAmount 0];
bar(y);
while (totalAmount > withdrawalAmount)
totalAmount = totalAmount + (interestRate * totalAmount);
withdrawalAmount = withdrawalAmount + (withdrawalAmount * inflationRate);
totalAmount = totalAmount - withdrawalAmount;
y = [y; totalAmount withdrawalAmount];
bar(y);
years = years + 1;
end
hold off;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.