How do you change the value of a subfunction variable?
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Walter Roberson
2017-9-22
You can call the function with different arguments:
value1 = .....
output1 = loanPayment( P, r, n_t, value1);
output2 = loanPayment( P, r, n_t, 100+value1);
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Financial Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!