function yout = GenerateTrajectories(M,n,N,R,vmax)
cvx_begin
syms t x1(t) x2(t);
y(t) = zeros(degree);
for i = 1:
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*pieces;
    Tg = M{i,1}(end);
    Aeq = zeros(1,c_length);
    Aeq(1) = 1;
    beq = M{i,2}(1);
    beq = [beq; M{i,2}(end)];
    newrow = zeros(1,c_length);
    for k = 1:degree
        newrow(c_length-degree+k) = Tg^(k-1);
    end
    Aeq = [Aeq; newrow];
    
    for k = 1:n-1
        newrow = zeros(1,c_length);
        for j = k:degree
            newrow(j+1) = k*0^(k-1);
        end
        Aeq = [Aeq; newrow];
        beq = [beq; [0 0]];
    end
    
    for k = 1:n-1
        newrow = zeros(1,c_length);
        for j = c_length-max(k)+k:c_length
            newrow(j+1) = k*0^(k-1);
        end
        Aeq = [Aeq; newrow];
        beq = [beq; M{i,2}(end)];
    end
    
    for s = 0:pieces-1
        for k = 1:n-1%continuity constraints
            newrow = zeros(1,c_length);
            for j = k:degree
                newrow(s*degree+j+1) = k*M{i,1}(s+1)^(k-1);
                newrow((s+1)*degree+j+1) = k*M{i,1}(s+1)^(k-1);
            end
            Aeq = [Aeq; newrow];
            beq = [0 0];
        end
    end
end
end