[英]Octave does not plot the function
I am preparing a graph of binding protein behavior.我正在准备结合蛋白行为图。
x = linspace(0,1,101)
y = ( x.*2.2*(10^-4))/(( x.+6.25*(10^-2))*(x.+2.2*(10^-2)))
plot(x,y)
Should result a bell curve(maybe) or a curve but i am getting a linear graph.应该导致钟形曲线(也许)或曲线,但我得到一个线性图。 I had checked with other software and resulting curve that function.
我已经用其他软件检查过,并得出了该函数的曲线。 Any help please?
请问有什么帮助吗?
You want to use ./
array division, not /
matrix division.您想使用
./
数组除法,而不是/
矩阵除法。
First, get some spaces up in here so it's easier to read.首先,在此处留出一些空格,以便于阅读。 And add semicolons to suppress that big output.
并添加分号来抑制大输出。
x = linspace(0, 1, 101);
y = (x.*2.2*(10^-4)) / ( ( x.+6.25*(10^-2)) * (x.+2.2*(10^-2)) );
plot(x, y)
Then stick it in a function for easier debugging:然后将其粘贴在一个函数中以便于调试:
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)
Now try it:现在试试:
>> 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
When you get a complaint like that about *
or /
, it usually means you're doing matrix operations when you really want the elementwise "array" operations .*
and ./
.当您收到关于
*
或/
类似抱怨时,通常意味着您正在执行矩阵运算,而您确实需要按元素进行“数组”运算.*
和./
。 Fix that and try it again:修复它并重试:
>> my_plot_of_whatever
>>
So what's going on here?那么这里发生了什么? Let's use the debugger!
让我们使用调试器!
>> 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
Aha.啊哈。 Your
y
is scalar, so it's using the same Y value for every X value.您的
y
是标量,因此它对每个 X 值使用相同的 Y 值。 That's because you're using /
matrix division, when you really want ./
array division.那是因为您正在使用
/
矩阵除法,而当您确实需要./
数组除法时。 Fix that:修复:
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)
Bingo.答对了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.