2016-08-16 102 views
1

如果我要畫一個sin(x)圖使用八度,我會做繪圖錯誤「內存耗盡或請求的大小太大」

x = -6:0.1:6; 
plot (x, sin(x)); 

和工作原理。

我想畫一個雙曲線函數,所以我嘗試

x = -6:0.1:6; 
plot (x, 1/(1+exp(-x))); 

但是這給了我

error: memory exhausted or requested size too large for range of Octave's index type -- trying to return to prompt 

我試着用x = -4:0.2:4;,這一次得到了

error: invalid conversion of NDArray to Matrix 
error: evaluating argument list element number 2 

什麼問題?

+0

嘗試'plot(x,1 ./(1 + exp(-x)));' –

+0

嗯。有用。重點是什麼?使用實數1(1)?哦,我現在看到明智的分工。 –

回答

1

問題出在​​。 MATLAB拋出的錯誤是:

Error using/
Matrix dimensions must agree. 

Carandraug's comment

倍頻失敗:

operator /: nonconformant arguments (op1 is 1x1, op2 is 1x121) 

你想要的是elementwise division(注意點):

x = -6:0.1:6; 
plot (x, 1./(1+exp(-x))); 

enter image description here

+0

我看到元素明智的點運算符只有當可以混淆時才需要。 (如分割,乘法......)。謝謝。 –

+1

@ChanKim'+','exp','sin'等已經執行元素明智的(檢查他們的文檔)。 '/'和'*'通常作爲*矩陣運算符*,所以你必須明確地告訴它明智的選擇,即在它們之前放一個點。 – Adriaan

+2

實際上,Octave也不能通過'operator /:nonconformant arguments(op1是1x1,op2是1x121)'進行該操作,並且不會廣播。 OP錯誤可能來自其他地方,無法在Octave中使用他的代碼進行復制(我嘗試過使用Octave 3.8,4.0和未發佈的4.1)。 – carandraug

相關問題