Figuring out my matlab code

Have this problem and I really need help with it.
An engineering company has run into financial difficulty on a project. You have been hired to audit the company’s books and come out with a recommendation for the company’s financiers. Specifically you want to determine the current financial standing of the company. Your audit team has gathered the following information: Checking account balance: $ 3,642.32 Savings account balance: $ 4,815.65 Pending transactions on the checking account: -2800.37, 900.32, -1452.92, -920.36, -1854.32, -1800.59, 799.99, 689.32, 556.81, 412.32, -4789.1, -2369.57. (Negative values indicate withdrawal and positive values indicate deposit). If the checking balance after any transaction falls below zero the bank assesses a fee of $100, and offsets the deficit by automatically subtracting from the savings account. If the savings balance is insufficient to offset the checking deficit, then a partial offset is made up to the amount available in the savings account, and the checking account goes into overdraft and is assessed a fee of $350 per transaction. The savings account is never allowed to go into overdraft.
a. Set up a script (.m) file to apply the pending transactions, and correctly assess low balance fees to checking and savings, where applicable. After the final transaction you should have the final updated account balances in both accounts. Run your script file. (20 points) b. Use the Matlab output command fprintf to display the checking balance, the savings balance, and the number of times each fee was assessed. (5 points) c. Plot two graphs of the savings balance and the checking balances versus the transaction number. You may plot both graphs on one figure using different colors or linetypes; or you may use the subplot method. (10 points) d. Provide comments in your Matlab code that would enable an independent non-specialist third party to follow along with what your program is attempting to achieve. (5 points)
Hints To Work Through This Problem Part a. • Create variables to hold the initial account balance amounts • Create an array to hold the transaction amounts • Use a For-Next loop to update the balance amounts after each transaction • Within the For-Next loop use an If-statement to check whether account balances will attract a fee after each transaction. In each case you will then apply the fee and update the balance amounts accordingly. • Within the For-Next loop create two arrays to store your updated balance amounts after each transaction. Part b. • Use the fprintf command to set up statements that will also pull the relevant variable and display it within the output statement Part d. • Create an array to hold the account balance amounts. After assessing applicable fees and updating the final values, use the Return function to output your final answer which will be an array.
this is my code
%setting known variables
checking_account_balance=3642.32;
savings_account_balance=4815.65;
%set pending
pending=[-2800.37 900.32 -1452.92 -920.36 -1854.32 -1800.59 799.9 689.32 556.81 412.32 -4789.1 -2369.57];
%initial fee for transaction while in zero
ifee= -100;
%fee for transactions while in neagtive while overdraft
ofee= -350;
%variable to track fees
tfee=0;
%setting known variables
checking_account_balance=3642.32;
savings_account_balance=4815.65;
%set pending
pending=[-2800.37 900.32 -1452.92 -920.36 -1854.32 -1800.59 799.9 689.32 556.81 412.32 -4789.1 -2369.57];
%initial fee for transaction while in zero
ifee= -100;
%fee for transactions while in neagtive while overdraft
ofee= -350;
%variable to track fees
tfee=0;
for i=1: length(pending)
%checking account balance array and savings account balance array
%create
if i == 1
%this line applies to the first transaction only and sets the
%saving balance variable
chkBal(i) = checking_account_balance + pending(i) ;
sBal(i)= savings_account_balance;
else
%for transctions from transaction number 2 to the end of
%pending array, this is if chkBal has enough money and makes
%sure sbal keeps up witht the i
chkBal(i) = chkBal(i - 1) + pending(i);
sBal(i)=sBal(i-1);
%check balance is drained all further transactions proceed to
%the savings account; check balance keeps up with i
if chkBal(i)<0 && pending(i)<0
sBal(i)=sBal(i-1)+pending(i);
chkBal(i)=chkBal(i-1);
end
%when a transaciton from pending is a positive integer it goes
%back into the checkings so checkings has money again and money
%can stop being pulled from savings
if chkBal(i) <0 && pending(i)>0
chkBal(i)=chkBal(i-1)+pending(i);
sBal(i)=sBal(i-1);
end
%when savings hits 0, all further transacitons go to the checkign
%thus putting the checkings in overdraft
if sBal(i)<0
chkBal(i)= chkBal(i-1) + pending(i);
sBal(i)=sBal(i-1);
end
end
%check if checking account is under $0 so fee needs to be charged
if chkBal(i) < 0 && pending(i) < 0
%if checking is 0 then all futher transactions go to savings
if sBal>0
sBal(i)=sBal(i-1) + ifee;
%track number of times fee charged
tfee= tfee + 1;
end
%once savings is depleted overdraft begins in the checkings
if sBal(i) < 0;
chkBal(i) = chkBal(i) - ofee ;
%track number of time the overdraft fee is charged
tfee = tfee + 1 ;
end
end
end
disp('Bank Statement')
disp('============================')
fprintf('\nChecking Balance is : %0.2f ',chkBal)
fprintf('\nSavings balance is: %0.2f ',sBal)
fprintf('\n Total fees charged %d ',tfee)
figure(1)
plot(chkBal,pending,'--Red');
figure(2)
plot(sBal,pending,'--Blue');

2 Comments

Nathaniel - even if this were not a homework/assignment question, please describe what problems you are having with the code. Is an error being raised, and if so, what is it? Are you stuck at a particular part of the problem, and if so, at what point? If you want help, you have to provide some details, and not just copy and paste your homework assignment into the question body along with some code that you have written.
Is there an error? Or do you have a question? Or are you just hoping someone will run this to double check your work? I don't know what to do with this.

Sign in to comment.

Answers (0)

Categories

Asked:

on 16 Feb 2015

Commented:

on 16 Feb 2015

Community Treasure Hunt

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

Start Hunting!