我在 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/