function [M,A,b] = mkp1d_timeDependent(x,k,f)

n = length(x)-1;
Atilda = zeros(n+1,n+1);
Mtilda = zeros(n+1,n+1);
btilda = zeros(n+1,1);

for p=1:n
    h = x(p+1)-x(p);
    Ap = (k(p)/h)*[1 -1;-1 1];
    Mp = (1/6)*h*[2,1;1,2];
    bp = f(p)*(h/2)*[1;1];
    idx = [p,p+1];
    Atilda(idx,idx) = Atilda(idx,idx) + Ap;
    Mtilda(idx,idx) = Mtilda(idx,idx) + Mp;
    btilda(idx) = btilda(idx) + bp;
end

A = Atilda(2:(end-1),2:(end-1));
M = Mtilda(2:(end-1),2:(end-1));
b = btilda(2:(end-1));
