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

int main()
{   
    int n = 10;
    unsigned int nodes = n+1;
    int rhs = 1;
    double a = 1.0;
    double alpha = 2.0;
    double gB = 1.0;

    double d = n + a/3.0/n;
    double s = - n + a / 6.0 / n;

    cout << d << endl;
    cout << s << endl;

    //Lapacke overwrites upper/lower diagonal so store twice 
    vector<double> upperdiagonal(n,s);
    vector<double> lowerdiagonal(n,s);
    vector<double> diagonal(nodes,2*d);
    vector<double> F(nodes,1.0/n);

    diagonal[0]=1.0;
    diagonal[n]=d+alpha;

    upperdiagonal[0] = 0.0;
    //

    F[0] = 0;
    F[n]= 1.0/n/2.0 +alpha*gB;
    

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

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

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

    return 0;

    
}  
