我想在 SciLab 中构造一个函数来计算向量每个元素的范数?

I'd like to construct a function in SciLab that calculates the norm of each element of the vector?

提问人:Lucas amaral 提问时间:8/23/2023 最后编辑:WolfieLucas amaral 更新时间:8/23/2023 访问量:32

问:

我是 Scilab 的新手,并试图构建一个函数来计算每个元素的范数,这是一个复数。

例如,向量为:

--> psi17
 psi17  = 

  -4.349D-17 - 0.0334936i
  -1.574D-17 - 0.0334936i
  -2.590D-17 - 9.206D-17i
  -2.590D-17 + 2.763D-17i
   0.4665064 - 7.819D-17i
   0.4665064 - 1.574D-17i
   5.365D-17 + 1.574D-17i
  -1.859D-18 + 7.992D-17i
  -0.5       + 0.125i    
   0.5       + 0.125i    
   7.633D-17 - 6.939D-18i
  -2.082D-17 + 7.980D-17i
   0.125     - 6.939D-17i
   0.125     + 1.388D-17i
  -2.082D-17 - 6.939D-18i
   3.469D-17 + 2.429D-17i

我想创建返回以下列向量的函数:

N =
 
  norm(psi17(1))
  norm(psi17(2))
  norm(psi17(3))
  ...
  norm(psi17(16))

我尝试实现以下功能:

function N = calc_norm(state)
    for i=1:length(state)
        N(i) = norm(state(i))
    end
endfunction

我收到错误:

--> exec('C:\Users\looka\Downloads\SimulacaoQuantum.sce', -1)
at line     3 of function calc_norm ( C:\Users\looka\Downloads\SimulacaoQuantum.sce line 21 )
at line   134 of executed file C:\Users\looka\Downloads\SimulacaoQuantum.sce

Invalid index.

我也尝试了这段代码:

function N = calc_norm(state)
    for i=1:length(state)
        N = [norm(state(i));N]
    end
endfunction

这个返回了错误:

--> exec('C:\Users\looka\Downloads\SimulacaoQuantum.sce', -1)
Warning : redefining function: calc_norm               . Use funcprot(0) to avoid this message
at line     3 of function calc_norm ( C:\Users\looka\Downloads\SimulacaoQuantum.sce line 21 )
at line   134 of executed file C:\Users\looka\Downloads\SimulacaoQuantum.sce

Invalid index.
数学 向量 SciLab

评论

2赞 Cris Luengo 8/23/2023
您可能想要使用该函数。 应该给出你想要的结果。absabs(psi17)

答: 暂无答案