Conjugate transpose: Difference between revisions

Content added Content deleted
m (C++ - changed formatting of output)
m (C++ - changed output formatting)
Line 345: Line 345:
for (const auto& row : values) {
for (const auto& row : values) {
assert(row.size() <= columns_);
assert(row.size() <= columns_);
std::copy(begin(row), end(row), &elements_[columns_ * i++]);
std::copy(begin(row), end(row), &elements_[i]);
i += columns_;
}
}
}
}
Line 409: Line 410:
const int precision = 6;
const int precision = 6;
out << std::fixed << std::setprecision(precision);
out << std::fixed << std::setprecision(precision);
out << '(' << std::setw(precision + 3) << c.real() << ','
out << std::setw(precision + 3) << c.real();
<< std::setw(precision + 3) << c.imag() << ')';
if (c.imag() > 0)
out << " + " << std::setw(precision + 2) << c.imag() << 'i';
else if (c.imag() == 0)
out << " + " << std::setw(precision + 2) << 0.0 << 'i';
else
out << " - " << std::setw(precision + 2) << -c.imag() << 'i';
return out.str();
return out.str();
}
}
Line 485: Line 491:
using matrix = complex_matrix<double>;
using matrix = complex_matrix<double>;


matrix matrix1(3, 3,
matrix matrix1(3, 3, {{{2, 0}, {2, 1}, {4, 0}},
{{{2, 0}, {2, 1}, {4, 0}},
{{2, -1}, {3, 0}, {0, 1}},
{{2, -1}, {3, 0}, {0, 1}},
{{4, 0}, {0, -1}, {1, 0}}});
{{4, 0}, {0, -1}, {1, 0}}});


double n = std::sqrt(0.5);
double n = std::sqrt(0.5);
matrix matrix2(3, 3,
matrix matrix2(3, 3, {{{n, 0}, {n, 0}, {0, 0}},
{{{n, 0}, {n, 0}, {0, 0}},
{{0, -n}, {0, n}, {0, 0}},
{{0, -n}, {0, n}, {0, 0}},
{{0, 0}, {0, 0}, {0, 1}}});
{{0, 0}, {0, 0}, {0, 1}}});


matrix matrix3(3, 3,
matrix matrix3(3, 3, {{{2, 2}, {3, 1}, {-3, 5}},
{{{2, 2}, {3, 1}, {-3, 5}},
{{2, -1}, {4, 1}, {0, 0}},
{{2, -1}, {4, 1}, {0, 0}},
{{7, -5}, {1, -4}, {1, 0}}});
{{7, -5}, {1, -4}, {1, 0}}});


test(matrix1);
test(matrix1);
Line 512: Line 515:
<pre>
<pre>
Matrix:
Matrix:
( 2.000000, 0.000000) ( 2.000000, 1.000000) ( 4.000000, 0.000000)
2.000000 + 0.000000i 2.000000 + 1.000000i 4.000000 + 0.000000i
( 2.000000,-1.000000) ( 3.000000, 0.000000) ( 0.000000, 1.000000)
2.000000 - 1.000000i 3.000000 + 0.000000i 0.000000 + 1.000000i
( 4.000000, 0.000000) ( 0.000000,-1.000000) ( 1.000000, 0.000000)
4.000000 + 0.000000i 0.000000 - 1.000000i 1.000000 + 0.000000i
Conjugate transpose:
Conjugate transpose:
( 2.000000,-0.000000) ( 2.000000, 1.000000) ( 4.000000,-0.000000)
2.000000 + 0.000000i 2.000000 + 1.000000i 4.000000 + 0.000000i
( 2.000000,-1.000000) ( 3.000000,-0.000000) ( 0.000000, 1.000000)
2.000000 - 1.000000i 3.000000 + 0.000000i 0.000000 + 1.000000i
( 4.000000,-0.000000) ( 0.000000,-1.000000) ( 1.000000,-0.000000)
4.000000 + 0.000000i 0.000000 - 1.000000i 1.000000 + 0.000000i
Hermitian: true
Hermitian: true
Normal: true
Normal: true
Line 524: Line 527:


Matrix:
Matrix:
( 0.707107, 0.000000) ( 0.707107, 0.000000) ( 0.000000, 0.000000)
0.707107 + 0.000000i 0.707107 + 0.000000i 0.000000 + 0.000000i
( 0.000000,-0.707107) ( 0.000000, 0.707107) ( 0.000000, 0.000000)
0.000000 - 0.707107i 0.000000 + 0.707107i 0.000000 + 0.000000i
( 0.000000, 0.000000) ( 0.000000, 0.000000) ( 0.000000, 1.000000)
0.000000 + 0.000000i 0.000000 + 0.000000i 0.000000 + 1.000000i
Conjugate transpose:
Conjugate transpose:
( 0.707107,-0.000000) ( 0.000000, 0.707107) ( 0.000000,-0.000000)
0.707107 + 0.000000i 0.000000 + 0.707107i 0.000000 + 0.000000i
( 0.707107,-0.000000) ( 0.000000,-0.707107) ( 0.000000,-0.000000)
0.707107 + 0.000000i 0.000000 - 0.707107i 0.000000 + 0.000000i
( 0.000000,-0.000000) ( 0.000000,-0.000000) ( 0.000000,-1.000000)
0.000000 + 0.000000i 0.000000 + 0.000000i 0.000000 - 1.000000i
Hermitian: false
Hermitian: false
Normal: true
Normal: true
Line 536: Line 539:


Matrix:
Matrix:
( 2.000000, 2.000000) ( 3.000000, 1.000000) (-3.000000, 5.000000)
2.000000 + 2.000000i 3.000000 + 1.000000i -3.000000 + 5.000000i
( 2.000000,-1.000000) ( 4.000000, 1.000000) ( 0.000000, 0.000000)
2.000000 - 1.000000i 4.000000 + 1.000000i 0.000000 + 0.000000i
( 7.000000,-5.000000) ( 1.000000,-4.000000) ( 1.000000, 0.000000)
7.000000 - 5.000000i 1.000000 - 4.000000i 1.000000 + 0.000000i
Conjugate transpose:
Conjugate transpose:
( 2.000000,-2.000000) ( 2.000000, 1.000000) ( 7.000000, 5.000000)
2.000000 - 2.000000i 2.000000 + 1.000000i 7.000000 + 5.000000i
( 3.000000,-1.000000) ( 4.000000,-1.000000) ( 1.000000, 4.000000)
3.000000 - 1.000000i 4.000000 - 1.000000i 1.000000 + 4.000000i
(-3.000000,-5.000000) ( 0.000000,-0.000000) ( 1.000000,-0.000000)
-3.000000 - 5.000000i 0.000000 + 0.000000i 1.000000 + 0.000000i
Hermitian: false
Hermitian: false
Normal: false
Normal: false