MATLAB Code IN MATLAB.You should save money for retirement from your very first
ID: 3821040 • Letter: M
Question
MATLAB Code IN MATLAB.You should save money for retirement from your very first paycheck. Luckily, your company has a 401k (retirement savings plan) that will allow you to put a certain percentage of your salary (myContributionPercentage) aside in an investment account to grow tax-deferred until retirement. • 50% of your contribution will be matched by your company up to 6% (i.e., your employer will not contribute more than 3% of your salary, even if you contribute > 6% of your salary.). • Your contribution (not including your employer’s contribution) cannot exceed $18000 per year. Write a function with the header: function [myContribution, employerContribution] = my401kCalculator(salary, myContributionPercentage) Which calculates how much money you will save per year in the 401k based on the percentage of your salary you set aside in the 401k. If your contribution exceeds $18000, the function should return $18000 plus the employer’s contribution. TEST CASES >> [a, b] = my401kCalculator(30000,.07) a =2100 b = 900 >> [a, b] = my401kCalculator(30000,.03) a = 900 b = 450 >> [a, b] = my401kCalculator(30000,.75) The contribution limit for your salary is 0.600% a = 18000 b = 900 >> [a, b] = my401kCalculator(60000,.25) a = 15000 b = 1800 >> [a, b] = my401kCalculator(60000,.045) a = 2700 b = 1350
Explanation / Answer
%matlab code
function [myContribution, employerContribution] = my401kCalculator(salary, myContributionPercentage)
if myContributionPercentage <= 0.06
myContribution = salary*myContributionPercentage;
if myContribution >= 18000
myContribution = 18000;
end
employerContribution = (myContribution/2);
else
myContribution = salary*myContributionPercentage;
if myContribution >= 18000
myContribution = 18000;
end
employerContribution = salary*(0.03);
end
end
[a, b] = my401kCalculator(30000,.07)
%a =2100 b = 900
[a, b] = my401kCalculator(30000,.03)
%a = 900 b = 450
[a, b] = my401kCalculator(30000,.75)
%The contribution limit for your salary is 0.600
% a = 18000 b = 900
[a, b] = my401kCalculator(60000,.25)
% a = 15000 b = 1800
[a, b] = my401kCalculator(60000,.045)
%a = 2700 b = 1350
%end matlab code
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.