Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.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
在Julia中,从矩阵访问的值不能用作函数中的参数_Julia - Fatal编程技术网

在Julia中,从矩阵访问的值不能用作函数中的参数

在Julia中,从矩阵访问的值不能用作函数中的参数,julia,Julia,首先,我有一个叫做渗透率的函数 # permeabiliy function # L is short for the Lable mu_0 = 4 * pi * 10^(-7); mu_r_core = 50; mu_r_air = 1; L = Int16; function permeability(L) if L in 1:4 if L !== 3 return mu = mu_r_air * mu_0 else

首先,我有一个叫做渗透率的函数

# permeabiliy function
# L is short for the Lable  
mu_0 = 4 * pi * 10^(-7);
mu_r_core = 50;
mu_r_air = 1;
L = Int16; 
function permeability(L)
    if L in 1:4
        if L !== 3 
            return mu = mu_r_air * mu_0
        else
            return mu = mu_r_core * mu_0
        end
    else
        println("null") #print output in a new line
    end
end
然后,我有一个称为域的矩阵,如下所示

 domain
 2392-element Array{Int16,1}:
 1
 1
 3
 1
...
当我调用渗透率(域[3])时,输出是

L = domain[3]
permeability(L)
输出是

1.2566370614359177e-6
6.283185307179588e-5
然而,当我简单地称之为渗透率(3)时

输出是

1.2566370614359177e-6
6.283185307179588e-5
因此,从矩阵域传递的值似乎只是“1”,但在这种情况下,域[3]应该是3,并且在这两种情况下的结果应该是相同的


有人能告诉我哪里错了吗?

问题是数组存储
Int16
,而
3
Int64
<代码>L==3要求
L
3
ie
Int64
的类型相同。你想要的是
L=3
。您的困惑可能来自以下事实:
=
==
相反,而
==
与Oscar的相反,Oscar是正确的,但是你的代码还有其他一些地方是错误的。最重要的可能是避免整数求幂(即,do
1e-7
而不是
10^(-7)
),并使函数类型稳定。(使用
@code\u(3)
检查推断的类型。)太棒了!谢谢你的精彩评论!我要去看看。一旦我有了新的发现,希望能尽快和你谈谈:)真的谢谢你,奥斯卡!它确实对我有用!下次我会更关注“!=”和“!=”:)