what exactly norm(x) function do?
显示 更早的评论
Good Afternoon,
I have to convert a part of my matlab code into C++.
I would be great if you can explain me what exactly norm(x) do on a vector of complex number so that I can write a C++ code for it.
I just asked a similar question on stack overflow but could not get much response.
Thank you in advance.
5 个评论
Manu Chaudhary
2022-9-21
移动:Adam Danz
2022-9-22
Steven Lord
2022-9-22
Are you performing the conversion to C++ manually or using MATLAB Coder? According to the Extended Capabilities section on its documentation page you can automatically generate C or C++ code from the norm function using MATLAB Coder.
Manu Chaudhary
2022-9-22
Manu Chaudhary
2022-9-22
编辑:Manu Chaudhary
2022-9-22
采纳的回答
更多回答(1 个)
Assuming you only care about p=2, If you already have code that computes norm(x) for real x, you can extend it to complex x via,
norm(x) = norm( [norm(real(x)), norm(imag(x)) ] )
which is easily verified below,
x=complex(rand(5,1), rand(5,1));
norm(x)
norm( [norm(real(x)), norm(imag(x)) ] )
Alternatively, if you have an implementation of abs, you could do norm(abs(x),p) which will work for any p-norm:
p=3;
norm(x,p)
norm(abs(x),p)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
