% Solve a system of equations
% Programmer: A. Trani

x2=0:1:250;        % Create a vector for x2
% Write the three equations solving for x1 as a function of x2 (defined
% above)

x1_1 = (270 - x2)/1.1;
x1_2 = (1260 - 6 * x2);
x1_3 = (580 - x2)/3;

% Plot the equations

plot(x1_1,x2,'-r',x1_2,x2,'-k',x1_3,x2,'-b')
    xlabel('Value of X_1')
    ylabel('Value of X_2')
    grid

    % To find the corner points use the polyxpoly function in Matlab

    % Supply two vertices of each line

    x2_vertex = [0 200];            % Define two random values for x2

    % Evaluate the vertices for x1

    x1_1_vertices = (270 - x2_vertex)/1.1;
    x1_2_vertices = (1260 - 6 * x2_vertex);
    x1_3_vertices = (580 - x2_vertex)/3;

 % Intersection of lines 1 and 2 
   [xi_12,yi_12] = polyxpoly(x1_1_vertices,x2_vertex,x1_2_vertices,x2_vertex);
   mapshow(xi_12,yi_12,'DisplayType','point','Marker','o')

    % Intersection of lines 1 and 3
   [xi_13,yi_13] = polyxpoly(x1_1_vertices,x2_vertex,x1_3_vertices,x2_vertex);
   mapshow(xi_13,yi_13,'DisplayType','point','Marker','o')

