尝试绘制函数 N*log2(N) 时出现八度错误

Octave error when trying to plot function N*log2(N)

我试图在 Octave 中绘制此函数,但出现了一个我不明白的错误。我已经成功绘制了其他函数,但由于某种原因,这个函数不起作用。

N=[1:1:50];

y1Values = N*log2(N);

%plot (n, y1Values, 'LineWidth',2, n,y2Values, 'LineWidth',3);

plot (N, [ y1Values' ], 'LineWidth',3);

legend("e^N");

这会产生此错误

error: asstemp: operator *: nonconformant arguments (op1 is 1x50, op2 is 1x50)

错误:调用自 在第 2 行第 10 列 asstemp

我不知道为什么 * 会成为问题。它没有与任何其他表达式一起使用。我需要用不同的方式编写表达式吗?

因为 N 是一个向量 log2(N) 也是 returns 一个向量,所以你试图将两个向量相乘。但是 * 是矩阵乘法。你想要的是元素乘法(.*):y1Values = N.*log2(N);