function HeatProblem = HP_Build(HeatProblem)

    npoin   = HeatProblem.Data.nelem+1;
    length  = HeatProblem.Data.endx - HeatProblem.Data.inix;

    h = length/HeatProblem.Data.nelem;
    for ipoin = 1:npoin
        HeatProblem.Solution.coord(ipoin) = HeatProblem.Data.inix + (ipoin-1)*h;
    end

    for ielem = 1:HeatProblem.Data.nelem
        lnods(ielem,1) = ielem;
        lnods(ielem,2) = ielem+1;
    end

    %Stiffnes matrix and rhs
    %stiffness: \HeatProblem.Data.kappa(\nabla v_h, \nabla u_h )
    %right hand side: <v_h , f> 
    HeatProblem.Matrices.K = zeros(npoin,npoin);
    HeatProblem.Matrices.F = zeros(npoin,1);
    for ielem = 1:HeatProblem.Data.nelem
        elmat = HeatProblem.Data.kappa*[ 1/h   -1/h;
                       -1/h    1/h];
        elrhs = ones(2,1)*HeatProblem.Data.source*h/2;

        for inode = 1:2
            ipoin = lnods(ielem,inode);
            for jnode = 1:2
                jpoin = lnods(ielem,jnode);
                HeatProblem.Matrices.K(ipoin,jpoin) = HeatProblem.Matrices.K(ipoin,jpoin) + elmat(inode,jnode);
            end
            HeatProblem.Matrices.F(ipoin) = HeatProblem.Matrices.F(ipoin) + elrhs(inode);
        end
    end

    %Boundary contribution (integration by parts, \HeatProblem.Data.kappa<v_h,n·\nabla HeatProblem.Solution.U>_\Gamma
    %Left
    if HeatProblem.Data.FixFluxesLeft == 0
        HeatProblem.Matrices.K(1,1) = HeatProblem.Matrices.K(1,1) + HeatProblem.Data.kappa*1/h;
        HeatProblem.Matrices.K(1,2) = HeatProblem.Matrices.K(1,2) - HeatProblem.Data.kappa*1/h;
    else
        HeatProblem.Matrices.F(1) = HeatProblem.Matrices.F(1) + HeatProblem.Data.LeftFluxes;
    end
    
    %Right
    if HeatProblem.Data.FixFluxesRight == 0
        HeatProblem.Matrices.K(npoin,npoin) = HeatProblem.Matrices.K(npoin,npoin) + HeatProblem.Data.kappa*1/h;
        HeatProblem.Matrices.K(npoin,npoin-1) = HeatProblem.Matrices.K(npoin,npoin-1) - HeatProblem.Data.kappa*1/h;
    else
        HeatProblem.Matrices.F(end) = HeatProblem.Matrices.F(end) + HeatProblem.Data.RightFluxes;
    end

        
    %Boundary conditions
    if HeatProblem.Data.FixLeft == 1
        HeatProblem.Matrices.K(1,:) = 0;
        HeatProblem.Matrices.K(1,1) = 1;
        HeatProblem.Matrices.F(1)   = HeatProblem.Data.LeftValue;

    end

    if HeatProblem.Data.FixRight == 1
        HeatProblem.Matrices.K(npoin,:) = 0;
        HeatProblem.Matrices.K(npoin,npoin) = 1;
        HeatProblem.Matrices.F(npoin)   = HeatProblem.Data.RightValue;
    end
end