function [K,F] = assemble_1D(x,lambda,f)
N = length(x);
K = zeros(N);
F = zeros(N,1);

for i = 1:N-1
    h = x(i+1)-x(i);
    xm = (x(i)+x(i+1))/2; %mid point evaluation
    lam = lambda(xm);
    Ke = lam/h * [1 -1; -1 1]; %exact P1 stiffness matrix
    xm = (x(i)+x(i+1))/2;
    Fe = f(xm)*h/2 * [1;1]; %mid point quadrature for RHS
    %assembly into global system
    K(i:i+1,i:i+1) = K(i:i+1,i:i+1) + Ke; 
    F(i:i+1) = F(i:i+1) + Fe;
end
end
