Problems 8
  1. Theory.
    1. How can you find out the declaration of struct gsl_odeiv2_system ?
      Hints:
      • #include<gsl/gsl_odeiv2.h> and gcc -E;
      • gsl-config --cflags and view.
    2. Which GSL functions (and how) can be used to add two gsl-vectors? Hint: there is more than one.
    3. Which GSL functions (and how) can be used to multiply a matrix and a vector?
    4. Which GSL functions (and how) can be used to add two matrices?
    5. Which GSL functions (and how) can be used to multiply two matrices?
    6. What does the function gsl_blas_dgemm do?
    7. How does one solve a system of linear algebraic equations 'Ax=y' with GSL? Name as many options as possible.
  2. Practice.
      1. Solve, using GSL, the linear system (from Numerisk Fysik 2011)
        x1 -x2 +2x3 =2
        2x2 -x3 =-1
        x1 +x2 +3x3 =3
        Hint: probably the best way to solve such system is via LU-decomposition using the GSL functions
        gsl_linalg_LU_decomp
        gsl_linalg_LU_solve
        
        or via QR-decomposition using the GSL functions
        gsl_linalg_QR_decomp
        gsl_linalg_QR_solve
        
        See
        GSL manual → Linear Algebra → LU Decomposition;
        GSL manual → Linear Algebra → QR Decomposition;
        GSL manual → Linear Algebra → Linear Algebra Examples.
      2. Check that you've got a correct solution.
    1. Consider the Lotka-Volterra equations (predator-prey equations) (from Numerisk Fysik 2011) (look it up in Wikipedia),
      dr/dt = r(α-βf)
      df/dt = -f(γ-δr)
      where r is the number of prey (for example, rabbits); f is the number of some predator (for example, foxes); dr/dt and df/dt represent the growth rates of the two populations over time; t represents time; and α, β, γ and δ are parameters describing the interaction of the two species.

      • Build a function for the Lotka-Volterra equations to be used as gsl_odeiv2_system.function .
        Hint:
        struct my_params {double alpha,beta,gamma,delta;};
        int lotka(double t, const double y[], double dydt[], void* params){
        	struct my_params p = *(struct my_params *)params;
        	dydt[0]= y[0]*(p.alpha-p.beta*y[1]);
        	dydt[1]=-y[1]*(p.gamma-p.delta*y[0]);
        return GSL_SUCCESS;
        }
        
      • Choose for example α=1, β=0.1, γ=2, δ=0.05, and solve the system numerically using GSL with the initial condition, for example, x=100, y=10. Plot the solutions x(t) and y(t) as functions of t on the same plot. Make also a parametric plot y versus x for different values of the parameters (let them approach the steady-state solution).