I need help on part c d and f. Question is in comments
Show older comments
%% Part A
dollars = 50000;
inflation = .02;
startAge = 23;
endAge = 65;
for year = startAge : 1 : endAge
dollars = dollars + (dollars * .02);
end
annual401kInterest = .08;
dollarsrequired = dollars / annual401kInterest;
fileID = fopen('Retirement.txt','w');
fprintf(fileID, '%.2f\r\n ', dollars);
fprintf(fileID, '%.2f\r\n ', dollarsrequired);
%% Part B
salary = 60000;
annualRaise = 0.05;
maxContribution = 19000;
personalContribution = [0.05; 0.1; 0.15; 0.2];
companyContribution = [0.05; 0.06; 0.06; 0.06];
totalDollars = 0;
interestGenerated = [0 0 0 0];
graphableDollars = [];
years = [];
for year = startAge : 1 : startAge + 30
salary = salary + (salary * annualRaise);
personalContributions = salary + personalContribution + maxContribution;
companyMatch = salary + companyContribution + maxContribution;
yearlyContribution = personalContributions + companyMatch ;
totalDollars = totalDollars + yearlyContribution;
interestGenerated = totalDollars * annual401kInterest;
totalDollars = totalDollars + interestGenerated;
for x = 1 : length(personalContribution)
fprintf(fileID, 'age: %g\tPersonal Contribution: $%.2f\r\n', year, personalContributions(x));
fprintf(fileID, 'age: %g\tCompany Contribtuions: $%.2f\r\n', year, companyMatch(x));
fprintf(fileID, 'age: %g\tInterest Generated: $%.2f\r\n', year, interestGenerated(x));
fprintf(fileID, 'age: %g\tCurrentDollars: $%.2f\r\n', year, totalDollars(x));
fprintf(fileID, '*********************************\n');
end
graphableDollars = [graphableDollars totalDollars];
years = [years year];
end
plot(years, graphableDollars)
xaxis
for x = 1 : length(personalContribution)
fprintf(fileID, 'total dollars for %.2f interest: $%.2f\r\n', personalContribution(x), totalDollars(x));
fprintf(fileID, 'You are going to be $%.2f dollars ahead of your goal\r\n', totalDollars(x) - dollarsrequired );
end
Answers (1)
Shivam Prasad
on 15 Oct 2019
0 votes
Hi Hunter,
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!