arguments - 请解释 Octave-Error : operator/: nonconformant arguments (op1 is 1x1, op2 是 1x10)

标签 arguments octave

我在 Octave 音程中运行某个脚本时遇到问题。 这是产生错误的代码:

#germanium
T=410:20:600;
x=linspace(400,410,100);
y=linspace(10^9,10^9,100);
k=8.5*10 .^(-5);
Eg=0.59;
Nc300=1.02*10^13;
Nc=Nc300*((T/300).^(3/2));
n=Nc*(e.^(-Eg/(2*k*T)));
plot(T,n,x,y,'m');
grid on
xlabel('Temprature');
ylabel('Electron Density n');
title('Germanium n(T)');

如标题所述,产生的错误如下: 错误:ger5:运算符/:不一致的参数(op1 是 1x1,op2 是 1x10) 我做了很多测试,我认为问题出在第 9 行的 T 变量:n=Nc*(e.^(-Eg/(2*k*T))); 没有它,代码运行良好。例如:

#germanium
T=410:20:600;
x=linspace(400,410,100);
y=linspace(10^9,10^9,100);
k=8.5*10 .^(-5);
Eg=0.59;
Nc300=1.02*10^13;
Nc=Nc300*((T/300).^(3/2));
n=Nc*(e.^(-Eg/(2*k*500)));
plot(T,n,x,y,'m');
grid on
xlabel('Temprature');
ylabel('Electron Density n');
title('Germanium n(T)');

在这种情况下,我只是将 T 替换为 500 ,代码运行得非常好。 遗憾的是 T,不能用某个数字代替,因为它是我图表中使用的变量。尽管我做了一些挖掘,但我从未设法完全理解此错误或如何修复它,因此非常感谢任何帮助。 谢谢。

最佳答案

添加一个 .在您的 *、/和 ^ 符号之前。这将确保 Octave 使用标量乘法而不是矩阵乘法。

n=Nc.*(e.^(-Eg./(2.*k.*T)));

关于arguments - 请解释 Octave-Error : operator/: nonconformant arguments (op1 is 1x1, op2 是 1x10),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56759719/

相关文章:

c++ - 何时在函数 args 中使用 const 和 const 引用?

当我在终端中输入 "octave"时,octave 打开 GUI

shared-libraries - 无法从源代码构建 Octave

java - 从 Java 启动 Cygwin 进程

haskell - 避免显式传递查找表

python - 在 python 的值中发送带有 & 字符的参数时出错?

python - Octave 测试模块

command-line - 如何抑制以 Octave 为单位的命令输出?

dart - 需要 1 个必需参数,但找到 0 个

c - 是什么, "passing argument 2 of ' strstr' 从没有强制转换的整数生成指针,"在 C 中的意思是