- Notifications
You must be signed in to change notification settings - Fork0
pedhmendes/gsl
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A good tool for scientific programmin in C is GNU Scientific Library (GSL). In this page I will leave some codes where some simple functions can be implemented. More informantion can be found in thislink.
If you don't have the library installed, open a terminal and type.
sudo apt-get updatesudo apt-get install libgsl-dev
GSL requires some special flags when compiling, take an example
gcc programa.c -lgsl -lgslcblas -lm -static
The last flag is important if you are using some cluster.
In physics there are some times we find some coupled ODE that we want to solve. Some can be a little bit trick to write an actual algorithm. We can use GSL to solve. In this repo you can find an code where I use theRunge-Kutta-Fehlberg method to solve theSIR epidemiology model. All methods and more info in ODE resolution can be foundhere.
Is not very hard to write linear congruential generator (LCG), but, for cientifical reasons, they can't be taken very serious. GSL library has a list of good RNG that we can use. In this repo you can find an example where I introduce some basic rng functions that GLS has to offer. I choose theMersenne Twister because it has and period of (219937 - 1) and good proprieties. More options of RNG can be foundhere.
It can be convinient that we generate numbers following some distribution, GSL can do it. This special generators requires and random number as seed, then they return another number following the desired distribution. So we need the RNG, we talked about this above, and we can use one of GSL. We are gonna give the pointer as argument of the function, is not difficult as it sounds. As example there is a code in this repo that uses theBox-Muller method to generate numbers following the Gaussian Distribution. You can check this making and histogram. More information about this generators and more avaiable distributions can be foundhere.