Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

Why isnt my graph?

1 view (last 30 days)
Hunter Steele
Hunter Steele on 9 Oct 2019
Closed: MATLAB Answer Bot on 20 Aug 2021
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
plot(years, graphableDollars)
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 (0)

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!