• Home
  • Blog
  • MEC 320 SUNYSB Gas & Steam Turbine Plant Mathematical Approach Programming Exercise

MEC 320 SUNYSB Gas & Steam Turbine Plant Mathematical Approach Programming Exercise

0 comments

I have a template made but I need you to put in the right numbers where the * are in the template
The answer should be for q1=15 and q2=10 so 25 at the end, but I need the program to provide that.

Please provide notes for the mathematical approach (solving by hand)

Please submit a .m file of the code and a separate file for the handwritten work

Here is the template code:

% Linear Programming with a Simplex Method Solver
%
% -----------Function description------------%
% cal_obj(): Calculates objective function values 
% GJE(): Performs Gauss-Jordan Eliminimation
% MRT(): Performs minimum ratio test
% RP(): Calculates relative profits
% display_tableau(): Prints tableau
% --------------------------------------------%
clc;
clear all;
format shortE;

% Index for temporal variables to save
temp_index1 = 0;
temp_index2 = 0;

% Set up the standard form of the simplex method
% A includes coefficients of q1, q2 + q3, q4, q5 (slack variables)
% in constraints
A = [* 1.2 * * *;
    * 0.4 * * *;
    * 1.7 * * *];
% b contains RHS of constraints
b = [*;*;*];

% Coefficient vector of the objectvie function
c = [1 1 * 0 0];

% Initial basic variables -> q3, q4, q5 (Slack variables)
basic = [3 4 5];
non_basic = [1 2];

% Initial heat flow rates
z = cal_obj(*,*,*);
fprintf('Initial heat rates = %0.2f kWn',z);

% Determine which non-basic variable gives the largest profit
c_bar = RP(*,*,*,*);

% Print Tableau 1 in command window
display_tableau(A,b,c_bar,z);

% This loop repeats until all the c_bar values become negative
while ( max(c_bar) > 0)
% Find the index where c_bar is maximum. The index will be the promoted
% variable
[~,temp_index1] = max(*);
q_promoted = temp_index1;

% Toward determining which basic variable should be demoted
temp_index2 = MRT(*,*,*);

% Find which variable should be demoted
q_demoted = basic(*);

% Update the new basic variables
% a: index of demoted variable, b: index of promoted variable
a = find(basic == *);
d = find(non_basic == *);
basic(a) = *;
non_basic(d) = *;

% With the new basic and non-basic variables, transform matrix A using the
% Gauss-Jordan elimination process
[A,b] = GJE(*,*,*,*);

%Determine which non-basic variable gives the largest profit
c_bar = RP(*,*,*,*);

% Calculation of the profit z
z = cal_obj(*,*,*);

% Display the tableau
display_tableau(A,b,c_bar,z);

end

% Print Tableau in command window
fprintf('Final Tableaun')
display_tableau(A,b,c_bar,z);

% Print the maximum profit
z = cal_obj(b,c,basic);
fprintf('The optimum heat rates,q = %0.2f kWn',z);

%% Gauss-Jordan elimination process
function [A,b] = GJE(a,q_promoted,A,b)
[m,n] = size(A);
% Temporal matrix 
A_new = zeros(m,n);
b_new = zeros(m,1);

for j = 1:n
    A_new(a,j) = A(a,j) / A(a,q_promoted);
end
b(a) = b(a)/A(a,q_promoted);

for i = 1:m
    for j = 1:n
        if ( i ~= a)
            A_new(i,j) = -(A(i,q_promoted)*A_new(a,j)) + A(i,j); 
        end
    end
    b_new(i) = -(b(a)*A(i,q_promoted))+b(i);
end
b_new(a) = b(a);

% Update matrices
A = A_new;
b = b_new;

end

%% Miminum Ratio Test
function index2 = MRT(C,MR,A)
% Function to calculate the minimum ratio
ratio = zeros(length(MR),1);
for i = 1:length(MR)
    ratio(i) = MR(i)/A(i,C);
end
% To find the least positive ratio, all zeros and negative values go to inf
ratio(ratio <= 0) = inf;
[~,index1] = min(ratio);
index2 = index1;
end

%% Relative Profit
function [c_bar] = RP(A,c,D,E)
% Function to calculate the relative profit
% This function returns c_bar
[~,n] = size(A);
c_bar = zeros(1,n);
for j = 1:length(D)
    temp = 0;
    for i = 1:length(E)
        temp = temp + ( c(E(i))*A( i,D(j) ) );
    end
    c_bar(D(j)) = c(D(j)) - temp;
end

end

%% Objective Value Calcuation
function z = cal_obj(A,B,MB)
n = length(MB);
z = 0;
for i = 1:n
    z = z + B(MB(i))*A(i);
end
end

%% Print Tableau
function display_tableau(A,b,c_bar,z)
% This function is to display tableau
[m,n]              = size(A);
tableau            = zeros(m+1,n+1);
tableau(1:m,1:n)   = A;
tableau(1:m,end)   = b(:);
tableau(end,1:n)   = c_bar(:);
tableau(end,end)   = z;
disp(tableau)
end

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}