Octave没有绘制函数

问题描述 投票:1回答:1

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

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

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

plot graph octave
1个回答
1
投票

怎么了

你想使用./阵列划分,而不是/矩阵划分。

如何调试这个

首先,在这里获得一些空间,以便更容易阅读。并添加分号以抑制大输出。

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

bad linear plot

那么这里发生了什么?我们来使用调试器吧!

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

答对了。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.