4 void m_trans(
const gsl_matrix*A, gsl_matrix*A_t){
5 gsl_matrix_transpose_memcpy(A_t,A);
8 void m_mult(
const gsl_matrix*A,
const gsl_matrix*B, gsl_matrix*AB){
9 gsl_blas_dgemm(CblasNoTrans,CblasNoTrans,1.0,A,B,0.0,AB);
12 void m_add_to(
const gsl_matrix*A, gsl_matrix*B){
17 gsl_matrix_scale(A,m);
20 void m_add (
const gsl_matrix*A,
const gsl_matrix*B, gsl_matrix*ApB){
21 gsl_matrix_memcpy(ApB,A);
22 gsl_matrix_add(ApB,B);
25 void m_inv(
const gsl_matrix*A, gsl_matrix*invA) {
26 unsigned int n = A->size1;
27 gsl_matrix *
m = gsl_matrix_alloc(n,n);
28 gsl_matrix_memcpy(m,A);
29 gsl_permutation * perm = gsl_permutation_alloc (n);
32 gsl_linalg_LU_decomp (m, perm, &s);
34 gsl_linalg_LU_invert (m, perm, invA);
35 gsl_permutation_free(perm);
39 double m_det(
const gsl_matrix*A) {
40 unsigned int n = A->size1;
41 gsl_matrix *
m = gsl_matrix_alloc(n,n);
42 gsl_matrix_memcpy(m,A);
43 gsl_permutation * perm = gsl_permutation_alloc (n);
45 gsl_linalg_LU_decomp (m, perm, &sign);
46 double det = gsl_linalg_LU_det(m, sign);
48 gsl_permutation_free(perm);
53 double m_dot(
const gsl_matrix*A,
const gsl_matrix*B) {
56 for(j=0;j<A->size2;j++)
57 sum +=
gmg(A,0,j)*
gmg(B,j,0);
63 gsl_poly_complex_workspace * w = gsl_poly_complex_workspace_alloc(n);
64 if(GSL_SUCCESS != gsl_poly_complex_solve (a, n, w, z)) {
67 gsl_poly_complex_workspace_free (w);
79 gsl_poly_complex_workspace * w = gsl_poly_complex_workspace_alloc(n);
80 if(GSL_SUCCESS != gsl_poly_complex_solve (a, n, w, z)) {
83 gsl_poly_complex_workspace_free (w);
85 printf(
"Solving the equation\n a = [");
86 for(
unsigned int i=0;i<n;i++) {
93 double lambda = 0;
int assigned = 0;
94 for (i = 0; i < n-1; i++) {
96 fprintf (stderr,
"root z%d = %+.18f + %+.18f i \n", i, z[2*i], z[2*i+1]);
100 if(!assigned || (z[2*i]>lambda)) {
106 fprintf (stderr,
"lambda = %+.18f \n", lambda);
108 fprintf(stderr,
"poly_greatest_real_root: Could not find real root for polynomial.\n");
109 fprintf(stderr,
"polynomial coefficients : ");
110 for (i = 0; i < n; i++)
111 fprintf(stderr,
" %lf ", a[i]);
112 fprintf(stderr,
"\nRoots:\n");
114 for (i = 0; i < n-1; i++)
115 fprintf (stderr,
"root z%d = %+.18f + %+.18f i \n", i, z[2*i], z[2*i+1]);
125 printf(
"%s= \n", str);
127 for(i=0;i<m->size1;i++) {
129 for(j=0;j<m->size2;j++)
130 printf(
"%e ",
gmg(m,i,j));
void m_trans(const gsl_matrix *A, gsl_matrix *A_t)
void m_scale(double m, gsl_matrix *A)
void m_display(const char *str, gsl_matrix *m)
int poly_greatest_real_root(unsigned int n, const double *a, double *root)
void m_add(const gsl_matrix *A, const gsl_matrix *B, gsl_matrix *ApB)
void m_inv(const gsl_matrix *A, gsl_matrix *invA)
double m_det(const gsl_matrix *A)
void m_mult(const gsl_matrix *A, const gsl_matrix *B, gsl_matrix *AB)
void m_add_to(const gsl_matrix *A, gsl_matrix *B)
int poly_real_roots(unsigned int n, const double *a, double *roots)
double m_dot(const gsl_matrix *A, const gsl_matrix *B)