function [loan_balance] = mortgage(amount,payment,rate,period)
% function [loan_balance] = mortgage(payment)
% this function returns the loan_balance on a mortgage
% given a specified monthly payment, annual interest rate and loan_period
%
% assumptions:
% start_amount = starting amount in dollars
% payment = monthly payment in dollars
% rate = annual interest rate, in percent
% period = number of years
%
% Benjamin W. Ong
% 2015/01/21
% calculate interest rate_per_month in decimal form
rate_per_month = (rate/12)/100;
% calculate number of months
loan_period = period * 12;
% initialize balance to starting amount
balance = amount;
% iterate through the loan period to find the end balance
for k = 1:loan_period
balance = balance * (1 + rate_per_month) - payment;
end
loan_balance = balance;