Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

% This script is has an error in it. Your goal is to find the error and % fix th

ID: 3598325 • Letter: #

Question

% This script is has an error in it. Your goal is to find the error and

% fix the program so it will work. Use the error message you get as a clue

% to fix the problem.

% The scritp uses the simple interest rate formula A=P(1+rt) to calculate

% the Accrued amount of money (A) that you would have investing some

% principle (P) at a given interest rate per year (r) for a given number of

% years. We will use this formulat to determine compound interest by

% putting it into a loop. Yes, there is a direct equation for calculating

% compound interest - look it up and see how close this method comes if you

% are curious.

% Set initial values:

P0 = 100; % One hundred dollars is the initial amount invested

rate= 0.03; % 3% annual interest rate

time = input ('how many years do you want to leave it there? ');

TotalAccrued = P0; % you start with your principle

for i=1:time

Accrued = P0(rate);

TotalAccrued = TotalAccrued + Acrued;

end

disp(TotalAccrued)

Explanation / Answer

Made changes to the code and commented the changes. Run it now.

P0 = 100; % One hundred dollars is the initial amount invested
rate= 0.03; % 3% annual interest rate
time = input ('how many years do you want to leave it there? ');
TotalAccrued = P0; % you start with your principle

for i=1:time
% Missing * between P0 and rate
Accrued = P0*(rate);
% Spelling mistake of Accrued
TotalAccrued = TotalAccrued + Accrued;
end
disp(TotalAccrued)

**Comment for any further queries. Upvote if the answer is satisfactory.