
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <lapacke.h>
using namespace std;


int main()
{   
    unsigned int ns[5] = {10,20,30,40,70};
    int p = 70;
    int rhs = 1;
    for(unsigned int i = 0; i< sizeof(ns)/sizeof(ns[0]); i++)
    {
        int n=ns[i];
        unsigned int nodes = n+1;

        vector<double> upperdiagonal(n,-n+p/2.0);
        vector<double> lowerdiagonal(n,-n-p/2.0);
        vector<double> diagonal(nodes,2*n);
        vector<double> F(nodes,0.0);
        upperdiagonal[0]=0.0;
        lowerdiagonal[n-1]=0.0;
        diagonal[0] = 1.0;
        diagonal[n] = 1.0;
        F[n] = 1.0;

        //Tridiagonal
        LAPACKE_dgtsv(LAPACK_COL_MAJOR,nodes,rhs,lowerdiagonal.data(),diagonal.data(),upperdiagonal.data(),F.data(),nodes);


         cout << "Solution u_h at nodes x_0..x_" << n << ":\n";
    
        for (unsigned int j = 0; j < nodes; ++j) {

            double xi = double(j) /double(n);
            cout << "u_h(" << xi << ") = " << F[j] << "\n";
            // F will be overwritten with sol
        }
    }

    /*
    From Methode  der finiten Elemente fuer Ingenieure:
    small n approximates pu' not good espicially if n < p/2=35 therefor this oscillation (see plot) occurs.
    */
    return 0;

    
}  
