Docsity

ENGR 200 (Computer applications in Engineering), Schemes and Mind Maps of Computer Science

Toggle sidebar
bg1
CODE:
% Assignment 10
% Ridwan_Abdi
% This code is used to calculate Uniform payment of given interest rate, years %
% and principal amount.
% clear all cache and windows
clear;
close all;
clc;
%input needed data
P = input('Enter principal in dollars: ');
years = input('Enter number of years: ');
%print header to screen
fprintf('****************************************************\n')
fprintf(' STUDENT LOAN PAYMENT CALCULATIONS\n\n')
%print input
formatSpec = 'Principal = $%.0f';
fprintf(formatSpec,P);
disp('\n\n')
%Calculations
n = years*12;
r = 1:0.5:9;
r = r/12;
R = interp1(1:numel(r), r, linspace(1,numel(r),n), 'nearest');
A = zeros(1,n);
for ii=1:n
A(ii) = P.*((R(ii).*((1+R(ii)).^n))/(((1+R(ii)).^n)-1));
end
output = [R; A];
disp('Interest Rate Monthly Payment');
formatSpec = ' %4.2f %7.2f\n';
fprintf(formatSpec, output);
%print results
% disp(' %4.2f %7.2f',r,A)
Results:
Enter principal in dollars: 300
Enter number of years: 2
****************************************************
STUDENT LOAN PAYMENT CALCULATIONS
Principal = $300\n\n
Interest Rate Monthly Payment
0.08 29.29
pf2

Partial preview of the text

Download ENGR 200 (Computer applications in Engineering) and more Schemes and Mind Maps Computer Science in PDF only on Docsity!

CODE:

% Assignment 10 % Ridwan_Abdi % This code is used to calculate Uniform payment of given interest rate, years % % and principal amount. % clear all cache and windows clear; close all; clc; %input needed data P = input('Enter principal in dollars: '); years = input('Enter number of years: '); %print header to screen fprintf('****************************************************\n') fprintf(' STUDENT LOAN PAYMENT CALCULATIONS\n\n') %print input formatSpec = 'Principal = $%.0f'; fprintf(formatSpec,P); disp('\n\n') %Calculations n = years12; r = 1:0.5:9; r = r/12; R = interp1(1:numel(r), r, linspace(1,numel(r),n), 'nearest'); A = zeros(1,n); for ii=1:n A(ii) = P.((R(ii).*((1+R(ii)).^n))/(((1+R(ii)).^n)-1)); end output = [R; A]; disp('Interest Rate Monthly Payment'); formatSpec = ' %4.2f %7.2f\n'; fprintf(formatSpec, output); %print results % disp(' %4.2f %7.2f',r,A)

Results:

Enter principal in dollars: 300 Enter number of years: 2


STUDENT LOAN PAYMENT CALCULATIONS Principal = $300\n\n Interest Rate Monthly Payment 0.08 29.

  • 0.12 39.
  • 0.12 39.
  • 0.17 51.
  • 0.21 63.
    1. 21 63.
  • 0.25 75.
  • 0.29 87.
  • 0.33 100.
  • 0.33 100.
  • 0.38 112.
  • 0.42 125.
  • 0.42 125.
  • 0.46 137.
  • 0.50 150.
  • 0.50 150.
  • 0.54 162.
  • 0.58 175.
  • 0.62 187.
  • 0.62 187.
  • 0.67 200.
  • 0.71 212.
  • 0.71 212.
  • 0.75 225.