Advertisement
hiddenGem

Loan Payments Over Time

Jun 29th, 2020
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.89 KB | None | 0 0
  1. %% Loan Payments Over Time
  2. % Calculates and prints loan payments
  3.  
  4. clc, clear
  5. % Inputs and Variables
  6. A0 = input('What is the initial loan amount?\n');
  7. R = input('What is the yearly interest rate?\n')/12;
  8. N = input('How many months do you want it to take?\n');
  9.  
  10. % Outputs and Equations
  11. P = A0*( R*( 1 + R )^N)/( ( 1+R )^N -1 );    
  12. n = 1;
  13. A = A0;
  14. while A > 0
  15.     I = A * R;
  16.     PP = P - I;
  17.     Afin = A - P + I;
  18.     Afin = round( Afin, 2);
  19.     I = round( I, 2 );
  20.     PP = round( PP, 2 );
  21.     fprintf( 'Payment %i: Initial Balance $%.2f Payment $%.2f Interest: $%.2f \n Principal Paid: $%.2f New Balance: $%.2f \n', n, A, I, P, PP, Afin)
  22.     n = n + 1;  
  23.     A = Afin;
  24. end         % while
  25. %{
  26. The user will be asked what their interest rate is for the year, it needs to be entered
  27.     in decimal form. The interest rate will be saved as a monthly rate. To change
  28.     this edit line 8.
  29. %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement