首页 > 解决方案 > 八度不绘制函数

问题描述

我正在准备一张结合蛋白行为的图表。

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

应该产生钟形曲线(也许)或曲线,但我得到一个线性图。我已经检查了其他软件并得出了该功能的曲线。请问有什么帮助吗?

标签: plotgraphoctave

解决方案


怎么了

您想使用./数组除法,而不是/矩阵除法。

如何调试这个

首先,在此处设置一些空格,以便于阅读。并添加分号来抑制大输出。

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

当您收到关于*or的此类投诉/时,通常意味着您正在执行矩阵运算,而您确实想要逐元素“数组”运算.*and ./。修复它并重试:

>> 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)

答对了。

在此处输入图像描述


推荐阅读