[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-gsl] How to use 'gsl_blas_dnrm2'?
From: |
Lukas Gradl |
Subject: |
[Help-gsl] How to use 'gsl_blas_dnrm2'? |
Date: |
Fri, 07 Jul 2017 21:35:55 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) |
Hello,
I am new to the GSL and C and I am having some trouble using the
function gsl_blas_dnrm2. I have the following example program:
---8<--- cut here -------------------- start --->8---
#include <stdio.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_cblas.h>
int main ()
{
gsl_vector *a = gsl_vector_alloc(3);
gsl_vector_set_all(a, 0.50);
double nrm;
nrm = gsl_blas_dnrm2(a);
fprintf(stdout, "%f\n", nrm);
gsl_vector_free(a);
return 0;
}
---8<--- cut here -------------------- end ----->8---
The output that I expect from this program is 0.8660254.
However, if I compile and run the program I get the following:
---8<--- cut here -------------------- start --->8---
address@hidden gcc -lgsl -lcblas -latlas -lm test.c
test.c: In function ‘main’:
test.c:11:9: warning: implicit declaration of function ‘gsl_blas_dnrm2’
[-Wimplicit-function-declaration]
nrm = gsl_blas_dnrm2(a);
^~~~~~~~~~~~~~
address@hidden ./a.out
24666208.000000
address@hidden ./a.out
45424736.000000
---8<--- cut here -------------------- end ----->8---
The output is actually different every time I run the program without
recompiling.
I tried to do the same using the CBLAS library that comes with GSL
instead of Atlas. In that case the output is always the number 3.0:
---8<--- cut here -------------------- start --->8---
address@hidden gcc -lgsl -lgslcblas -lm test.c
test.c: In function ‘main’:
test.c:11:9: warning: implicit declaration of function ‘gsl_blas_dnrm2’
[-Wimplicit-function-declaration]
nrm = gsl_blas_dnrm2(a);
^~~~~~~~~~~~~~
address@hidden ./a.out
3.000000
address@hidden ./a.out
3.000000
---8<--- cut here -------------------- end ----->8---
How would I use this function so that it gives the correct result? My
guess is that I am making a trivial mistake somewhere but I can't find
it.
Thank you for your help!
Best,
Lukas
signature.asc
Description: PGP signature
- [Help-gsl] How to use 'gsl_blas_dnrm2'?,
Lukas Gradl <=