what exactly norm(x) function do?
Mostrar comentarios más antiguos
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 comentarios
Manu Chaudhary
el 21 de Sept. de 2022
Movida: Adam Danz
el 22 de Sept. de 2022
Steven Lord
el 22 de Sept. de 2022
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
el 22 de Sept. de 2022
Manu Chaudhary
el 22 de Sept. de 2022
Editada: Manu Chaudhary
el 22 de Sept. de 2022
Respuesta aceptada
Más respuestas (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)
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
