Julia中单位根的计算
我想在Julia中有一个算法,取决于$n$,这样它可以生成单位的n根 (1,w^{1},w^{2},…,w^{n-1}。这样,对于每个1\leq i\leq n,我们有(w^{i})^{n}-1=0) 非常感谢您的合作Julia中单位根的计算,julia,algebra,Julia,Algebra,我想在Julia中有一个算法,取决于$n$,这样它可以生成单位的n根 (1,w^{1},w^{2},…,w^{n-1}。这样,对于每个1\leq i\leq n,我们有(w^{i})^{n}-1=0) 非常感谢您的合作 julia> roots(n) = map(cispi, range(0, 2, length=n+1)[1:end-1]) roots (generic function with 1 method) julia> roots(8) 8-element Vecto
julia> roots(n) = map(cispi, range(0, 2, length=n+1)[1:end-1])
roots (generic function with 1 method)
julia> roots(8)
8-element Vector{ComplexF64}:
1.0 + 0.0im
0.7071067811865476 + 0.7071067811865476im
0.0 + 1.0im
-0.7071067811865476 + 0.7071067811865476im
-1.0 + 0.0im
-0.7071067811865476 - 0.7071067811865476im
0.0 - 1.0im
0.7071067811865476 - 0.7071067811865476im
您可以编写root\u exp(n)=exp.(im.*range(0,2pi,length=n+1)[1:end-1])
,但对于纯虚参数,cis
的效率略高于exp
。而且,cispi
稍微更精确,或者至少,当您期望它们时,它更有可能为您提供漂亮的整数,如上所示
您可以编写root\u exp(n)=exp.(im.*range(0,2pi,length=n+1)[1:end-1])
,但对于纯虚参数,cis
的效率略高于exp
。而且,cispi
稍微更精确,或者至少,当您期望它们时,它更有可能为您提供漂亮的整数,如上所示