I have a subfunction called loanPayment that I want to have a specific value.
To specify: loanPayment is a function containing the inputs (P,r,n_t,R) and the output (A). However, in my function, I want to use the same loanPayment function to calculate output(1) but with a value of 100+min payment instead of R.
I apologize if this is a stupid question but I have looked around already and am not completely convinced with my search results.
The following is my code:
function [ output ] = studentLoan( P,r,n_t )%Calculates the metrics of a loan
% P: principle value of the loan
% r: interest rate
% n_t: the number of payments at which we assess the value of the loan
% output(1): the amount left in the loan if $100 more than the minimum
% payment is made every compounding period after n_t periods and every
% payment is made
% output(2): the minimum payment needed to prevent the loan from growing
output=zeros(1,5);output(1)=??????;output(2)=@minPayment; function [ R ] = minPayment(P,r,n_t) % calculates minimum payment needed to prevent the loan from growing
R=(P*(1+r).^n_t)/symsum((1+r)^k,k,0,n_t-1); end function [ num ] = timeToPay (P,r,R) % Calculates how many payments it would take to pay off the loan
% given a rate of payment R
% num = number of payments
end endfunction [ A ] = loanPayment( P,r,n_t,R)A=evalPoly([P,-R*ones(1,n_t)],[n_t:n_t-1],1+r);end
Best Answer