2011-06-03 75 views
0

我有一個繪製3d功能的問題 - 當我輸入數據時,如果手動執行計算,我會得到一個線性圖形,並且這些值不會相加。我相信這個問題與使用矩陣有關。使用Octave繪製3D功能

INITIAL_VALUE=999999; 
INTEREST_RATE=0.1; 
MONTHLY_INTEREST_RATE=INTEREST_RATE/12; 

# ranges 
down_payment=0.2*INITIAL_VALUE:0.1*INITIAL_VALUE:INITIAL_VALUE; 
term=180:22.5:360; 

[down_paymentn, termn] = meshgrid(down_payment, term); 

# functions 
principal=INITIAL_VALUE - down_payment; 

figure(1); 
plot(principal); 
    grid; 
    title("Principal (down payment)"); 
    xlabel("down payment $"); 
    ylabel("principal $ (amount borrowed)"); 

monthly_payment = (MONTHLY_INTEREST_RATE*(INITIAL_VALUE - down_paymentn))/(1 - (1 + MONTHLY_INTEREST_RATE)^-termn); 

figure(2); 
mesh(down_paymentn, termn, monthly_payment); 
    title("monthly payment (principal(down payment))/term months"); 
    xlabel("principal"); 
    ylabel("term (months)"); 
    zlabel("monthly payment"); 

像我說的第二個數字不像我預期的那樣積累。我如何更改我的公式以正確呈現?

回答

1

我想你的腳本,並得到了以下錯誤:

error: octave_base_value::array_value(): wrong type argument `complex matrix' 
... 

monthly_payment是一個複雜的矩陣(和它不應該是)。

我想問題是電力運營商^。您應該使用.^進行逐個元素的操作。

從文檔:

x^y
x ** y
Power operator. If x and y are both scalars, this operator returns x raised to the power y. If x is a scalar and y is a square matrix, the result is computed using an eigenvalue expansion. If x is a square matrix. the result is computed by repeated multiplication if y is an integer, and by an eigenvalue expansion if y is not an integer. An error results if both x and y are matrices.

The implementation of this operator needs to be improved.

x .^ y
x .** y
Element by element power operator. If both operands are matrices, the number of rows and columns must both agree.

+0

謝謝您的回答 - 我會試試看,當我的倍頻已經不段錯誤... – Walter 2011-09-20 11:54:22