19 for (
int i = 0; i <
size; ++i) {
24 for (
int r = 0; r <
N - 1; ++r) {
27 double inv_rr_re = m_lu[
re(r, r)] / norm_rr;
28 double inv_rr_im = -m_lu[
im(r, r)] / norm_rr;
31 for (
int i = r + 1; i <
N; ++i) {
32 double ir_re = m_lu[
re(i, r)];
33 double ir_im = m_lu[
im(i, r)];
34 m_lu[
re(i, r)] = ir_re * inv_rr_re - ir_im * inv_rr_im;
35 m_lu[
im(i, r)] = ir_re * inv_rr_im + ir_im * inv_rr_re;
36 ir_re = m_lu[
re(i, r)];
37 ir_im = m_lu[
im(i, r)];
39 for (
int j = r + 1; j <
N; ++j) {
40 double& rj_re = m_lu[
re(r, j)];
41 double& rj_im = m_lu[
im(r, j)];
42 m_lu[
re(i, j)] -= ir_re * rj_re - ir_im * rj_im;
43 m_lu[
im(i, j)] -= ir_re * rj_im + ir_im * rj_re;
54 for (
int i = 0; i <
N; ++i) {
55 for (
int j = 0; j < i; ++j) {
61 for (
int i = N - 1; i >= 0; --i) {
62 for (
int j = i + 1; j <
N; ++j) {
67 double real = vec[
re(i)];
68 double imag = vec[
im(i)];
70 vec[
re(i)] = (real *
m_lu[
re(i, i)] + imag *
m_lu[
im(i, i)]) * inv_norm;
71 vec[
im(i)] = (imag *
m_lu[
re(i, i)] - real *
m_lu[
im(i, i)]) * inv_norm;
79 for (
int i = 0; i <
size; ++i) {
82 for (
int i = 0; i <
N; ++i) {
94 for (
int i = 0; i <
N; ++i) {
95 for (
int r = 0; r < i; ++r) {
96 double& luir_re =
m_lu[
re(i, r)];
97 double& luir_im =
m_lu[
im(i, r)];
98 for (
int j = 0; j <
N; ++j) {
99 mat[
re(i, j)] -= luir_re * mat[
re(r, j)] - luir_im * mat[
im(r, j)];
100 mat[
im(i, j)] -= luir_re * mat[
im(r, j)] + luir_im * mat[
re(r, j)];
106 for (
int i = N - 1; i >= 0; --i) {
107 for (
int r = i + 1; r <
N; ++r) {
108 double& luir_re =
m_lu[
re(i, r)];
109 double& luir_im =
m_lu[
im(i, r)];
110 for (
int j = 0; j <
N; ++j) {
111 mat[
re(i, j)] -= luir_re * mat[
re(r, j)] - luir_im * mat[
im(r, j)];
112 mat[
im(i, j)] -= luir_re * mat[
im(r, j)] + luir_im * mat[
re(r, j)];
115 for (
int j = 0; j <
N; ++j) {
117 double real = mat[
re(i, j)];
118 double imag = mat[
im(i, j)];
120 mat[
re(i, j)] = (real *
m_lu[
re(i, i)] + imag *
m_lu[
im(i, i)]) * inv;
121 mat[
im(i, j)] = (imag *
m_lu[
re(i, i)] - real *
m_lu[
im(i, i)]) * inv;
133 for (
int i = 0; i <
N; ++i) {
134 double old_re = real;
135 double old_im = imag;
136 real = old_re *
m_lu[
re(i, i)] - old_im *
m_lu[
im(i, i)];
137 imag = old_re * m_lu[
im(i, i)] + old_im * m_lu[
re(i, i)];
140 return cmplx(real, imag);
void mult_inverse(double *mat)
std::valarray< double > m_lu
void get_inverse(double *mat_inv)
void set_matrix(const double *mat)