Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 为什么我在计算n时得到矩阵尺寸误差?_Matlab_Function - Fatal编程技术网

Matlab 为什么我在计算n时得到矩阵尺寸误差?

Matlab 为什么我在计算n时得到矩阵尺寸误差?,matlab,function,Matlab,Function,您能告诉我以下代码有什么问题吗? function [n]=calculate_n(p,delta) e = 1.6*power(10,-19); k = 1.38*power(10,-23); T = 298; co = 3.25*power(10,13)*e*power(10,4); er=12.5; eo=1.0; Nv=3*power(10,13); us = log((p*e)/sqrt(2*k*T*er*e

您能告诉我以下代码有什么问题吗?

    function [n]=calculate_n(p,delta)
    e = 1.6*power(10,-19);
    k = 1.38*power(10,-23);
    T = 298;

    co = 3.25*power(10,13)*e*power(10,4);

    er=12.5;
    eo=1.0;
    Nv=3*power(10,13);

    us = log((p*e)/sqrt(2*k*T*er*eo*Nv))*2*k*T;
    tmp = delta+(e*e*p)/co+us;
    n = 1/(exp((tmp))+1);
end

我在计算n时得到矩阵尺寸误差。请帮帮我

来电者:

e = 1.6*power(10,-19);
x = logspace(13,18);
y=calculate_n(x,0.2*e);
semilogx(x,y,'-s');
grid on;
只需替换
n=1/(exp((tmp))+1
n=1./(exp(tmp)+1)。但是要注意,
tmp
对于这些值来说太小了,以至于
exp(tmp)
总是1。另外,
tmp
周围还有一个多余的括号,您可能需要检查是否正确放置了它们

编辑:
原因是
A/B
试图为
x
解线性方程组
A*x=B
,这不是您想要的。它抛出了一个错误,因为它要求两个变量具有相同的列数
A./B
执行您想要的元素矩阵除法。但是,如果
A
B
是单数
A/B=A./B
。有关更多信息,请参阅。

是p向量还是增量向量?对于p=0.5和delta=2,它对我来说运行得很好……我已经添加了调用方代码。只需替换
n=1/(exp((tmp))+1)
n=1./(exp(tmp)+1)
-但是要注意,
tmp
对于这些值来说太小了,以至于
exp(tmp)
始终是1。另外,tmp周围还有一个多余的括号,你可能想检查一下你是否把它们放对了。非常感谢。它起作用了。总是很乐意帮忙。我把它放在一个答案中,这样你就可以接受/关闭它。目前,你提供了一个解决方案,但没有解释。我知道,好的答案应该能教会我们一些东西。简要解释一下
/
/
之间的区别,以及
/
导致矩阵尺寸错误的原因,怎么样?(免责声明:我几乎不知道MATLAB。)@honk你是对的,不是我最好的作品。是否要编辑它?或者编辑被接受的答案是非常不受欢迎的?如果你不完全改变解决方案,那么我看不出有任何问题。随时欢迎改进您的帖子!