簡體   English   中英

Octave 不繪制函數

[英]Octave does not plot the function

我正在准備結合蛋白行為圖。

x = linspace(0,1,101)
y = ( x.*2.2*(10^-4))/(( x.+6.25*(10^-2))*(x.+2.2*(10^-2)))
plot(x,y)

應該導致鍾形曲線(也許)或曲線,但我得到一個線性圖。 我已經用其他軟件檢查過,並得出了該函數的曲線。 請問有什么幫助嗎?

怎么了

您想使用./數組除法,而不是/矩陣除法。

如何調試這個

首先,在此處留出一些空格,以便於閱讀。 並添加分號來抑制大輸出。

x = linspace(0, 1, 101);
y = (x.*2.2*(10^-4)) / ( ( x.+6.25*(10^-2)) * (x.+2.2*(10^-2)) );
plot(x, y)

然后將其粘貼在一個函數中以便於調試:

function my_plot_of_whatever
x = linspace(0, 1, 101);
y = (x.*2.2*(10^-4)) / ( ( x.+6.25*(10^-2)) * (x.+2.2*(10^-2)) );
plot(x, y)

現在試試:

>> my_plot_of_whatever
error: my_plot_of_whatever: operator *: nonconformant arguments (op1 is 1x101, op2 is 1x101)
error: called from
    my_plot_of_whatever at line 3 column 3

當您收到關於*/類似抱怨時,通常意味着您正在執行矩陣運算,而您確實需要按元素進行“數組”運算.*./ 修復它並重試:

>> my_plot_of_whatever
>>

糟糕的線性圖

那么這里發生了什么? 讓我們使用調試器!

>> dbstop in my_plot_of_whatever at 4
ans =  4
>> my_plot_of_whatever
stopped in /Users/janke/Documents/octave/my_plot_of_whatever.m at line 4
4: plot(x, y)
debug> whos
Variables in the current scope:

   Attr Name        Size                     Bytes  Class
   ==== ====        ====                     =====  =====
        x           1x101                      808  double
        y           1x1                          8  double

啊哈。 您的y是標量,因此它對每個 X 值使用相同的 Y 值。 那是因為您正在使用/矩陣除法,而當您確實需要./數組除法時。 修復:

function my_plot_of_whatever
x = linspace(0, 1, 101);
y = (x.*2.2*(10^-4)) ./ ( ( x.+6.25*(10^-2)) .* (x.+2.2*(10^-2)) );
plot(x, y)

答對了。

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM