I'm working with an array of complex numbers a
and an array of real numbers b
(as double).
typedef std::complex<double> Complex;
std::valarray<Complex> a(1024);
std::valarray<double> b(1024);
std::valarray<double> modulus = std::abs(a); // problem 1
std::valarray<Complex> modulus2 = std::abs(a); // this works but uses 2 times more memory :(
std::valarray<Complex> c = a * b; // problem 2
I encounter two problems (live runnable demo here) :
For memory management purpose, as the absolute value (or "modulus") is a real number, it should be possible to store it as a
std::valarray<double>
. But here it doesn't work : there is an errorconversion from 'std::_Expr<std::_UnClos<std::_Abs, std::_ValArray, std::complex<double> >, std::complex<double> >' to non-scalar type 'std::valarray<double>' requested
. How to storemodulus
as astd::valarray<double>
?It should be possible to multiply
a
byb
and store the result as an array of complex numbers. But there is this error :no match for 'operator*' (operand types are 'std::valarray<std::complex<double> >' and 'std::valarray<double>')
. How to do this multiplication of arrays properly?