function yout = GenerateTrajectories(M,n,N,R,vmax)
syms t;
%y = [x1 x2];
%Q = int(norm(diff(y,t,n))^2,t,0,M{1,1}(end));
for i = 1:length(M)
    degree = 2*n-1;
    pieces = length(M{i,1});
    c_length = (degree+1)*pieces;
    Tg = M{i,1}(end);
    Aeq = zeros(1,c_length);
    Aeq(1) = 1;
    beq = M{i,2}(1);
    newrow = zeros(1,c_length);
    for k = 0:degree
        newrow(c_length-degree+k) = Tg^k;
    end
    Aeq = [Aeq; newrow];
    beq = [beq; M{i,2}(end)];
    for k = 1:n-1
       newrow = zeros(1,c_length);
       for n = 0:degree
           newrow(n+1) = subs(diff(t^n,t,k),t,0);
       end
       Aeq = [Aeq; newrow];
       beq = [beq; 0 0];
    end
    for k = 1:n-1
       newrow = zeros(1,c_length);
       for n = 0:degree
           newrow(c_length - degree - 1 + n+1) = subs(diff(t^n,t,k),t,Tg);
       end
       Aeq = [Aeq; newrow];
       beq = [beq; 0 0];
    end
    for s = 0:pieces-1
        for k = 1:n-1%continuity constraints
            newrow = zeros(1,c_length);
            for n = 0:degree
                newrow(s*degree+j+1) = subs(diff(t^n,t,k),t,M{i,1}(s+1));
                newrow((s+1)*degree+j+1) = -subs(diff(t^n,t,k),t,M{i,1}(s+1));
            end
            Aeq = [Aeq; newrow];
            beq = [0 0];
        end
    end
    
end
end