フィルターのクリア

User-defined monthly loan payment function issues

9 ビュー (過去 30 日間)
Sydney
Sydney 2024 年 5 月 12 日
コメント済み: Sydney 2024 年 5 月 12 日
Hello! I am trying to create a very simple user-defined function to calculate monthly payments on a loan, but I am unsure why my function is returning "0". I am sure it must be a silly formatting error, but I would appreciate any help pointing out my mistake! Thank you!
% amort returns monthly payment of a loan given the loan amount, annual interest
% rate, and length of loan
% P=loan amount
% r=annual interest rate (in percent)
% N=length of loan in years
function [M]=amort(P,r,N)
M=P*((r/1200)/(1-(1+(r/1200)))^((-12)*N))
  2 件のコメント
Walter Roberson
Walter Roberson 2024 年 5 月 12 日
What are some example parameters to the call?
Sydney
Sydney 2024 年 5 月 12 日
One example I ran used P=260000, r=6.75, N=15
Is this what you were asking by parameters?
I called it using:
amort(260000,6.75,15)

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2024 年 5 月 12 日
M=P*((r/1200)/(1-(1+(r/1200)))^((-12)*N))
12 1 2 3 4 321 23 2 10
That has a sub-expression (1-(1+(r/1200))) . That sub-expression simplifies to -(r/1200) . So you effectively have
P * ( (r/1200)/(-r/1200)^(-12*N) )
which is
P * (-r/1200)^(12*N + 1)
(or something similar)
It seems unlikely that is what you wanted.
  3 件のコメント
Walter Roberson
Walter Roberson 2024 年 5 月 12 日
You entered it wrong in MATLAB.
M = P * (r/1200) ./ (1 - (1+r/1200).^(-12*N))
Sydney
Sydney 2024 年 5 月 12 日
Thank you for your help!!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by