Esempio n. 1
0
void expm(gsl_matrix_complex * L, gsl_complex t, gsl_matrix * m)
     {
    int i,j,s;
	gsl_vector_complex *eval = gsl_vector_complex_alloc(4);
	gsl_matrix_complex *evec = gsl_matrix_complex_alloc(4, 4);
	gsl_eigen_nonsymmv_workspace * w = gsl_eigen_nonsymmv_alloc(4);
	gsl_matrix_complex *evalmat = gsl_matrix_complex_alloc(4, 4);
	gsl_matrix_complex *vd = gsl_matrix_complex_alloc(4, 4);
	gsl_complex one = gsl_complex_rect(1, 0);
	gsl_complex zero = gsl_complex_rect(0, 0);

	gsl_matrix_complex *K = gsl_matrix_complex_alloc(4, 4);
	gsl_permutation *p = gsl_permutation_alloc(4);
	gsl_vector_complex *x = gsl_vector_complex_alloc(4);

	gsl_vector_complex_view bp;
	gsl_complex z;

	gsl_eigen_nonsymmv(m, eval, evec, w);
	gsl_eigen_nonsymmv_sort(eval, evec, GSL_EIGEN_SORT_ABS_DESC);

	gsl_eigen_nonsymmv_free(w); // clear workspace

	for (i = 0; i < 4; i++)
	{
		gsl_complex eval_i = gsl_vector_complex_get(eval, i);
		gsl_complex expeval = gsl_complex_mul(eval_i,t);
		expeval = gsl_complex_exp(expeval);
		gsl_matrix_complex_set(evalmat, i, i, expeval);
	}

	gsl_vector_complex_free(eval); // clear vector for eigenvalues

	// v'L'=De'v'
	gsl_blas_zgemm(CblasTrans, CblasTrans, one, evalmat, evec, zero, vd);
	gsl_matrix_complex_transpose(evec);//transpose v

	gsl_matrix_complex_memcpy(K,evec);

	for (i = 0; i < 4; i++)
	{
		bp = gsl_matrix_complex_column(vd, i);
		gsl_linalg_complex_LU_decomp(evec, p, &s);
		gsl_linalg_complex_LU_solve(evec, p, &bp.vector, x);
			for (j = 0; j < 4; j++)
			{
				z = gsl_vector_complex_get(x, j);
				gsl_matrix_complex_set(L,i,j,z); //'through the looking glass' transpose
			}
		gsl_matrix_complex_memcpy(evec,K);
	}


	gsl_permutation_free(p);
	gsl_vector_complex_free(x);
	gsl_matrix_complex_free(vd);
	gsl_matrix_complex_free(evec);
	gsl_matrix_complex_free(evalmat);
	gsl_matrix_complex_free(K);
}
Esempio n. 2
0
/*!
Returns true if the input matrix is Hermitian.
*/
bool IsHermitian(const gsl_matrix_complex * const M)
{
	gsl_matrix_complex *N;
	gsl_complex zm, zn;
	int i, j;
	bool isHerm = true;

	N = gsl_matrix_complex_alloc(M->size1, M->size2);

	for(i = 0; i < M->size1; ++i)
	{
		for(j = 0; j < M->size2; ++j)
		{
			zm = gsl_matrix_complex_get(M, i, j);
			GSL_SET_COMPLEX(&zn, GSL_REAL(zm), ((-1)*GSL_IMAG(zm)));
			gsl_matrix_complex_set(N, i, j, zn);
		}
	}

	gsl_matrix_complex_transpose(N);

	for(i = 0; i < M->size1; ++i)
	{
		for(j = 0; j < M->size2; ++j)
		{
			zm = gsl_matrix_complex_get(M, i, j);
			zn = gsl_matrix_complex_get(N, i, j);

			if( GSL_REAL(zm) != GSL_REAL(zn) ||
			    GSL_IMAG(zm) != GSL_IMAG(zn) )
			{
				isHerm = false;
				goto _exit;
			}
		}
	}

_exit:
	gsl_matrix_complex_free(N);

	return isHerm;
}
Esempio n. 3
0
bool Matrix_Transpose(gsl_matrix_complex *A){
 	gsl_matrix_complex_transpose(A);
	return true;
	}