Question: this is a mathlab code the white spot on the image can be edited but the grey spots of this code cannot be changed how

this is a mathlab code the white spot on the image can be edited but the grey spots of this code cannot be changed how can i fix this code it is not meeting one of the grading criteria Annuity this matter proves to be related to the entire code meaning the problem has to be reset where everything on the white spot must be changed to make it work
immy starts an annuity with a principal value of R1000000(one million Rands) and plans to withdraw a fixed amount each month, starting one
month after opening the annuity account. Jimmy expects to draw R20000(twenty thousand Rands) from the annuity every month, for 15 years
(fifteen years). Suppose the monthly interest rate is fixed at 1.9% and that interest is computed each month on the annuity before the
withdrawal made. The annuity is overdrawn when its value drops below zero.
Answer the following questions:
Will the value of the annuity drop to zero before the 15 year time span ends?
For how many months will Jimmy be able to withdraw R20000 without overdrawing on the account?
What is the value of the annuity after the last withdrawal of R20000, before the account is overdrawn?
Use the code below to help answer these questions. The function
AnnuityRecursive( p,w,r,n)
takes as input the principle value p, the monthly withdrawal amount w, the iterest rate r and the number of months n , and returns a vector t of
months and a vector a of annuity values such that a(i) is the value of the anuity at time t( i).
Note: This task will require several iterations to complete and several iterations to determine the necessary values. The code provided will
generate a plot of your simulation values to help you complete the task. You can run your code on the system before submitting your soulution
for grading.
Script o.
% set constants
P =1000000; % Principal in Rands
W=20000; % Withdrawal in Rands
R=0.019; % Monthly interest rate (1.9%)
N =180; % Number of months (15 years)
% pretty print outputs
pretty('Principal', P);
pretty('Withdrawl', w):
pretty('Rate , R);
pretty('Months :N);
% Call AnnuityRecursive to construct the t an a vectors
[t a]= AnnuityRecursive(P, W, R, N):
% Answer questions below:
% Will the value of the annuity drop to zero before the 20 year time span ends?
% Yes: 1
% No: 0
Q1=1; % Q1=1(Yes) if any value is below zero, 0(No) otherwise
% For how many months will Jimny be able to withdraw R20000 without overdrawing
% on the account?
Q2= find(a >0,1, 'last'): % Find the last month where the balance is positive
% What is the value of the annuity after the last withdrawal of R20000, before
% the account is overdrawn?
if Q2 length(a)
Q3= a(Q2): % Value before the overdraft happens
else
Q3=0;
end
% This is a generic evaluation check. You cannot edit this.
[Q4t Q4a]= AnnuityRecursive(123456,12345,12/1000,96);
% Plot the results.
plot(t, a,'ob'):
xlabel('time [months]');
ylabel('value [Rands]');
title('Remaining Annuity value over time. ');
grid;
% define functions
function [t a]= AnnuityRecursive(p, w, r, n)
% Initialize time vector and annuity value vector
t =1:n+1; % Time vector from 0 to n months
a = zeros(1,n+1); % Initialize annuity values to zero
a(1)= pi % Initial principal value
% Loop through each month to calculate annuity values
for i =2:n
a(i)=a(i-1)*(1+ r)- w; % Calculate next annuity value
if a(i)0% If balance goes negative, stop
a(i)=0; % Set value to zero if it goes negative
break: % Exit loop
end
end
end
% Use the following functions to pretty print arrays and values
function pretty(s, a)
end
fprintf(['%s:' repmat('%1d ',1, numel(a))'
'], s, a):
Output
this is a mathlab code the white spot on the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!