Skip to content

Instantly share code, notes, and snippets.

@kdungs
Created November 28, 2012 21:18
Show Gist options
  • Save kdungs/4164607 to your computer and use it in GitHub Desktop.
Save kdungs/4164607 to your computer and use it in GitHub Desktop.
Testing GSL
P = test_gsl
OBJECTS = test_gsl.c
CFLAGS = -g -Werror -O3 -std=gnu11 `pkg-config --cflags gsl`
LDLIBS = `pkg-config --libs gsl`
CC = gcc-mp-4.7
$(P): $(OBJECTS)
clean:
rm $(P)
rm -r *.dSYM
#include <stdio.h>
#include <gsl/gsl_const_mksa.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_vector.h>
int main()
{
// Testing Vectors
gsl_vector *v1 = gsl_vector_alloc(3);
gsl_vector_set(v1, 0, 1);
gsl_vector_set(v1, 1, 1);
gsl_vector_set(v1, 2, 1);
gsl_vector *v2 = gsl_vector_alloc(3);
gsl_vector_set(v2, 0, 1);
gsl_vector_set(v2, 1, 2);
gsl_vector_set(v2, 2, 3);
gsl_vector_add(v1, v2);
//gsl_vector_fprintf(stdout, v1, "%g");
gsl_vector_free(v1);
gsl_vector_free(v2);
// Testing Matrices
gsl_matrix *m1 = gsl_matrix_alloc(3, 3);
gsl_matrix_set_identity(m1);
gsl_matrix *m2 = gsl_matrix_alloc(3, 3);
gsl_matrix_set(m2, 1, 1, 10);
gsl_matrix_add(m1, m2);
//gsl_matrix_fprintf(stdout, m1, "%g");
gsl_matrix_free(m1);
gsl_matrix_free(m2);
// Testing Constants
printf("h = %.18e\n", GSL_CONST_MKSA_PLANCKS_CONSTANT_H);
printf("ħ = %.18e\n", GSL_CONST_MKSA_PLANCKS_CONSTANT_HBAR);
// Testing Random Number Generation
gsl_rng *r = gsl_rng_alloc(gsl_rng_ranlxs2);
for (unsigned int i=0; i<100; i++) {
printf("%.18e\n", gsl_rng_uniform(r));
}
gsl_rng_free(r);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment