Clear Filters
Clear Filters

How do you change the value of a subfunction variable?

1 view (last 30 days)
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
end
function [ A ] = loanPayment( P,r,n_t,R)
A=evalPoly([P,-R*ones(1,n_t)],[n_t:n_t-1],1+r);
end

Accepted Answer

Walter Roberson
Walter Roberson on 22 Sep 2017
You can call the function with different arguments:
value1 = .....
output1 = loanPayment( P, r, n_t, value1);
output2 = loanPayment( P, r, n_t, 100+value1);

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!