Learning by doing: Reading books and trying to understand the (code) examples
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

45 lines
1.2 KiB

#include "cplx.h"
#include <gsl/gsl_blas.h>
#include <gsl/gsl_complex_math.h>
gsl_vector_complex *cvec_dot_gslcplx(gsl_vector_complex *v, gsl_complex x) {
gsl_vector_complex *out = gsl_vector_complex_alloc(v->size);
for (size_t i=0; i < v->size; i++) {
gsl_vector_complex_set(out, i, gsl_complex_mul(x, gsl_vector_complex_get(v, i)));
}
return out;
}
gsl_vector_complex *vec_dot_gslcplx(gsl_vector *v, gsl_complex x) {
gsl_vector_complex *out = gsl_vector_complex_alloc(v->size);
for (size_t i=0; i < v->size; i++) {
gsl_vector_complex_set(out, i, gsl_complex_mul_real(x, gsl_vector_get(v, i)));
}
return out;
}
gsl_vector_complex *cvec_dot_c(gsl_vector_complex *v, complex double x) {
return cvec_dot_gslcplx(v, gsl_cplx_from_c99(x));
}
gsl_vector_complex *vec_dot_c(gsl_vector *v, complex double x) {
return vec_dot_gslcplx(v, gsl_cplx_from_c99(x));
}
complex double ddot(complex double x, complex double y) {
return x * y;
}
void gsl_vector_complex_print(gsl_vector_complex *v) {
for (size_t i = 0; i < v->size; i++) {
gsl_complex x = gsl_vector_complex_get(v, i);
printf("%4g + %4gi%c", GSL_REAL(x), GSL_IMAG(x), i < v->size-1 ? '\t' : '\n');
}
}