CH3133 - Modelling, Simulation and Optimisation for Chemical Engineering
LECTURE 13 – WEEK 13
LINEAR PROGRAMMING &
SOLVING ODE
Ho Chi Minh City University of technology
Lecturer: Aqsha, Khoa Ta Dang
Ho Chi Minh City University of technology
Institut Teknologi Bandung
2024
Image Souurce: Licdn.com
LAST WEEK MATERIAL
Optimizations
PROBLEM-SOLVING
Image:
Convex Optimisation
Newton Method
▪ The necessary condition for f(x) to have an optimum is that f ’(x) = 0
▪ Applying Newtons method to solve f ’(x) = 0
Image:
NUMERICAL METHOD
Image:
NUMERICAL METHOD
Image:
NUMERICAL METHOD
Image:
ROOT FINDING METHODs
BISECTION METHOD
The bisection method, which is alternatively called binary chopping,
interval halving, or Bolzano’s method, is one type of incremental
search method in which the interval is always divided in half.
In general, if f(x) is real and continuous in
the interval from xl to xu and f(xl) and f(xu)
have opposite signs, that is,
f(xl) f(xu) < 0
then there is at least one real root between
xl and xu.
Image:
BISECTION METHOD
Image:
BISECTION METHOD
We stop the process if the condition is satisfied (% relative error)
xrnew is the root for the present iteration and xrold is the root from the
previous iteration.
Image:
BISECTION METHOD
Thus, after six iterations ɛa finally falls below ɛs = 0.5%, and the
computation can be terminated.
Image:
THE SECANT METHOD
Graphical depiction of the Secant
method. This technique is similar to
the Newton-Raphson technique in
the sense that an estimate of the
root is predicted by extrapolating a
tangent of the function to the
x axis.
However, the secant method uses a
difference rather than a derivative to
estimate the slope (Newton-Raphson).
Image:
THE SECANT METHOD
(Newton-Raphson Method) (Secant Method)
Image:
THE SECANT METHOD
Notice that the approach requires two initial estimates of x. However,
because f(x) is not required to change signs between the estimates, it is
not classified as a bracketing method.
Image:
THE OTHER METHODS
THE FALSE-POSITION METHOD
SIMPLE FIXED-POINT ITERATION
THE NEWTON-RAPHSON METHOD
Image:
LINEAR PROGRAMMING
Linear programming (LP) is an optimization approach that deals with
meeting a desired objective such as maximizing profit or minimizing
cost in the presence of constraints such as limited resources.
For a maximization problem, the objective function is generally
expressed as
The constraints can be represented generally as
Image:
LINEAR PROGRAMMING
Problem Statement
The following problem is developed from the area of chemical or petroleum engineering. However, it
is relevant to all areas of engineering that deal with producing products with limited resources.
Develop a linear programming formulation to maximize the profits for this operation.
Image:
LINEAR PROGRAMMING
Develop a linear programming formulation to maximize the profits for
this operation!
Solution
The engineer operating this plant must decide how much of each gas
to produce to maximize profits. If the amounts of regular and premium
produced weekly are designated as x1 and x2, respectively, the total
weekly profit can be calculated as:
Image:
LINEAR PROGRAMMING
The constraints can be developed in a similar fashion. For example,
the total raw gas used can be computed as
This total cannot exceed the available supply of 77 m 3/week and
working hour 80 hr/week, so the constraint can be represented as
Image:
LINEAR PROGRAMMING
First, the constraints can be plotted on the
solution space. For example, the first
constraint can be reformulated as a line by
replacing the inequality by an equal sign and
solving for x2
Next, the objective function can be added to
the plot. To do this, a value of Z must
be chosen. For example, for Z = 0, the
objective function becomes
Image:
LINEAR PROGRAMMING
Now, since we are interested in maximizing
Z, we can increase it to say, 600, and the
objective function is
Increasing the value of the objective function
moves the line away from the origin.
Because the line still falls within the solution
space, our result is still feasible. Z can keep
increasing until a further increase will take
the objective beyond the feasible region.
Image:
LINEAR PROGRAMMING
The maximum value of Z corresponds to approximately 1400. At this
point, x1 and x2 are equal to approximately 4.9 and 3.9, respectively.
Thus, the graphical solution tells us that if we produce these quantities
of regular and premium, we will reap a maximum profit of about 1400.
Image:
THIS WEEK MATERIAL
Linear Programming and Solving ODEs
LINEAR PROGRAMMING
Problem Statement
The following problem is developed from the area of chemical or petroleum engineering. However, it
is relevant to all areas of engineering that deal with producing products with limited resources.
Develop a linear programming formulation to maximize the profits for this operation.
Image:
LINEAR PROGRAMMING
Develop a linear programming formulation to maximize the profits for
this operation!
Solution
The engineer operating this plant must decide how much of each gas
to produce to maximize profits. If the amounts of regular and premium
produced weekly are designated as x1 and x2, respectively, the total
weekly profit can be calculated as:
Image:
LINEAR PROGRAMMING
The constraints can be developed in a similar fashion. For example,
the total raw gas used can be computed as
This total cannot exceed the available supply of 77 m 3/week and
working hour 80 hr/week, so the constraint can be represented as
Image:
LINEAR PROGRAMMING
First, the constraints can be plotted on the
solution space. For example, the first
constraint can be reformulated as a line by
replacing the inequality by an equal sign and
solving for x2
Next, the objective function can be added to
the plot. To do this, a value of Z must
be chosen. For example, for Z = 0, the
objective function becomes
Image:
LINEAR PROGRAMMING
Now, since we are interested in maximizing
Z, we can increase it to say, 600, and the
objective function is
Increasing the value of the objective function
moves the line away from the origin.
Because the line still falls within the solution
space, our result is still feasible. Z can keep
increasing until a further increase will take
the objective beyond the feasible region.
Image:
LINEAR PROGRAMMING
The maximum value of Z corresponds to approximately 1400. At this
point, x1 and x2 are equal to approximately 4.9 and 3.9, respectively.
Thus, the graphical solution tells us that if we produce these quantities
of regular and premium, we will reap a maximum profit of about 1400.
Image:
THE SIMPLEX METHOD
Now let us suppose that our problem
involves a unique solution. The graphical
approach might suggest an enumerative
strategy for hunting down the maximum.
From Fig. X, it should be clear that the
optimum always occurs at one of the
corner points where two constraints meet.
Such a point is known formally as an
extreme point. Thus, out of the infinite
number of possibilities in the decision
space, focusing on extreme points clearly
narrows down the possible options.
Image:
THE SIMPLEX METHOD
The simplex method is predicated on the assumption that the optimal solution will be
an extreme point. To do this, the constraint equations are reformulated as equalities
by introducing what are called slack variables.
As the name implies, a slack variable measures how much of a constrained resource
is available, that is, how much “slack” of the resource is available.
7𝑥1 + 11𝑥2 ≤ 77
We can define a slack variable S1 as the amount of raw gas that is not used for a
particular production level (x1, x2). If this quantity is added to the left side of the
constraint, it makes the relationship exact
7𝑥1 + 11𝑥2 + 𝑆1 ≤ 77
Image:
THE SIMPLEX METHOD
A different slack variable is developed for each constraint equation, resulting in what
is called the fully augmented version,
𝑀𝑎𝑥𝑖𝑚𝑖𝑧𝑒 𝑍 = 150𝑥1 + 175𝑥2
Constraints
Notice how we have set up the four equality equations so that the unknowns are
aligned in columns.
Image:
THE SIMPLEX METHOD
Normally we had n equations with n unknowns, to solve the system (Algebraic Soln)
The system of equations below is underspecified or underdetermined, that is, it has
more unknowns than equations. In general terms, there are n structural variables
(that is, the original unknowns), m surplus or slack variables (one per constraint),
and n 1 m total variables (structural plus surplus). For the gas production problem
we have 2 structural variables, 4 slack variables, and 6 total variables. Thus, the
problem involves solving 4 equations with 6 unknowns.
Image:
THE SIMPLEX METHOD
Specifically, every feasible point has 2
variables out of 6 equal to zero. For
example, the five corner points of the area
ABCDE have the following zero values:
Image:
THE SIMPLEX METHOD
This observation leads to the conclusion that the extreme points can be determined
from the standard form by setting two of the variables equal to zero. In our example,
this reduces the problem to a solvable form of 4 equations with 4 unknowns.
For example, for point E, setting x1 = S4 = 0 reduces the standard form to
Which can be solved for x2 = 6, S1 = 11, S2 = 32, and S3 = 9.Together with x1 = S4 =
0, these values define point E.
Image:
THE SIMPLEX METHOD
Image:
THE SIMPLEX METHOD
Image:
THE SIMPLEX METHOD
Before proceeding to the next step, the beginning information can now be
summarized in a convenient tabular format called a tableau. As shown below, the
tableau provides a concise summary of the key information constituting the linear
programming problem.
Notice that for the purposes of the tableau, the objective function is expressed as
Z - 150x1 - 175x2 - 0S1 - 0S2 - 0S3 - 0S4 = 0
Image:
THE SIMPLEX METHOD
In order to solve this set of equations, similar algorithm such as Gauss-Jordan
elimination is used. It involves a series of iterations until the final solution is reached.
Image:
THE SIMPLEX METHOD
Recall that the basic strategy behind Gauss-Jordan involved converting the pivot element to 1 and
then eliminating the coefficients in the same column above and below the pivot element.
For this example, the pivot row is S2 (the leaving variable) and the pivot element is 10 (the coefficient
of the entering variable, x1). Dividing the row by 10 and replacing S2 by x1 gives
Next, the x1 coefficients in the other rows can be eliminated. For example, for the objective function
row, the pivot row is multiplied by -150 and the result subtracted from the first row to give
Image:
THE SIMPLEX METHOD
Similar operations can be performed on the remaining rows to give the new tableau,
This tableau can then be used to chart our next, and in this case final, step. Only one more variable,
x2, has a negative value in the objective function, and it is therefore chosen as the entering variable.
According to the intercept values (now calculated as the solution column over the coefficients in the x 2
column), the first constraint has the smallest positive value, and therefore, S1 is selected as the
leaving variable.
Image:
THE SIMPLEX METHOD
Start Excel Spreadsheet to solve the linear programming problem
Image:
THE SIMPLEX METHOD
Input all the available data including its constraint and set the solver
Image:
THE SIMPLEX METHOD
Input all the available data including its constraint and set the solver
Image:
MATLAB: LINPROG
x = linprog(f,A,b) solves min f'*x such that A*x ≤ b.
% Coefficients of the objective function
f = [-150, -175]; % Negative because linprog minimizes by default
% Coefficients of the constraints: Matrix A has size 4x2 (4 rows, 2 columns), Matrix b has size 4x1
A = [7, 11; % Raw gas constraint
10, 8; % Production time constraint
1, 0; % Regular storage constraint
0, 1]; % Premium storage constraint
b = [77; % Raw gas availability
80; % Production time availability
9; % Regular product storage limit
6]; % Premium product storage limit
% Lower bounds (non-negativity constraints)
lb = [0, 0];
% Solve the linear programming problem: Matrix x has size 2x1 (2 rows, 1 column)
[x, fval] = linprog(f, A, b, [], [], lb);
% Display the results
fprintf('Optimal production of Regular product (x1): %.2f tonnes\n', x(1));
fprintf('Optimal production of Premium product (x2): %.2f tonnes\n', x(2));
fprintf('Maximum profit: %.2f\n', -fval); % Negate fval to get the maximized value
Image:
MATLAB: LINPROG
Explanation of the Code
1.Objective Function (f):
1. The objective is to maximize Z=150x1+175x2.
2. In MATLAB, the linprog function minimizes the objective function, so we use the negative of the coefficients
[−150,−175].
2.Constraints (A and b):
1. Each row of matrix A corresponds to the coefficients of a constraint.
2. Each element of vector b is the right-hand side of the corresponding constraint.
3. The constraints are:
1. 7x1+11x2≤77 (raw gas availability)
2. 10x1+8x2≤80 (production time availability)
3. x1≤9 (storage for regular product)
4. x2≤6 (storage for premium product)
Image:
MATLAB: LINPROG
Non-negativity Constraints (lb):
•Both x1 and x2 must be non-negative (x1,x2≥0), represented by lb = [0, 0].
Solve the Linear Program:
•The linprog function solves the problem.
•x contains the optimal values of x1 and x2 (amounts of the Regular and Premium products to produce).
•fval is the minimized value of the objective function. Since we used the negative of the profit function, we negate fval to
get the maximum profit.
Output:
•The optimal production quantities for Regular and Premium products are displayed.
•The maximum profit is also displayed.
Image:
THE SIMPLEX METHOD
Image:
THE SIMPLEX METHOD
Image:
THE SIMPLEX METHOD
Image:
SOLVING ODEs
Image:
SOLVING ODEs
Plots of (a) y versus x and (b) dy/dx versus
x for the function
If we differentiate Eq. above
we obtain an ODE:
Image:
SLOPE METHOD
An ODE
New value = old value
+ slope ╳ step size
Image:
EULER METHOD
An ODE
This formula is referred to as
Euler’s (or the Euler-Cauchy or the
point-slope) method. A new value
of y is predicted using the slope
(equal to the first derivative at the
original value of x) to extrapolate
linearly over the step size h
Image:
EULER METHOD
Use Euler’s method to numerically integrate
from x = 0 to x = 4 with a step size of 0.5.
The initial condition at x = 0 is y = 1
Recall that the exact solution is given by Eq. below
Image:
EULER METHOD
Image:
EULER METHOD
The approximate values were computed using Euler’s method with a step size of 0.5. The local error
refers to the error incurred over a single step.
Image:
EULER METHOD
Image:
EULER METHOD
Image:
OTHER METHOD (HEUN’s)
The Heun method is a predictor-corrector approach.
As with similar iterative methods, a termination
criterion for convergence of the corrector is provided
by
Image:
OTHER METHOD (HEUN’s)
Example:
Use Heun’s method to integrate y’ = 4e0.8x - 0.5y from x = 0 to x = 4 with a step size
of 1. The initial condition at x = 0 is y = 2.
Analytical Solution:
Image:
OTHER METHOD (HEUN’s)
First, the slope at (x0, y0) is calculated as
The numerical solution is obtained by using the predictor to obtain an
estimate of y at 1.0:
To improve the estimate for yi+1, we use the value y10 to predict the slope at
the end of the interval
Image:
OTHER METHOD (HEUN’s)
which can be combined with the initial slope to yield an average slope over the
interval from x = 0 to 1
which is closer to the true average slope of 4.1946. This result can then be
substituted into the corrector to give the prediction at x = 1
Image:
OTHER METHOD (HEUN’s)
Now this estimate can be used to refine or correct the prediction of y1 by substitut-
ing the new result back into the right-hand side of Heun’s Eq
which represents an absolute percent relative error of 1.31 percent. This result, in
turn, can be substituted back into Heun’s Eq. to further correct:
Image:
OTHER METHOD (HEUN’s)
Image:
OTHER METHOD (HEUN’s)
Comparison of true and approximate values of the integral of
y’ = -2x3 + 12x2 - 20x + 8.5, with the initial condition that y = 1 at x = 0. The
approximate values were computed using three versions of second-order RK
methods with a step size of 0.5.
Image:
OTHER METHOD (HEUN’s)
Image:
RUNGE-KUTTA METHOD
Image:
RUNGE-KUTTA METHOD
Image:
RUNGE-KUTTA METHOD
Use the classical fourth-order RK method to integrate
using a step size of h = 0.5 and an initial condition of y = 1 at x = 0.
Image:
RUNGE-KUTTA METHOD
Image:
RUNGE-KUTTA METHOD
Use the classical fourth-order RK method to integrate
using a step size of h = 0.5 and an initial condition of y = 1 at x = 0.
Image:
PLEASE CONTACT ME!
AQSHA
Assistant (Research) Professor
Dept. of Bioenergy Engineering & Chemurgy
Dept. of Chemical Engineering
Institut Teknologi Bandung, Indonesia
Waste to Energy Conversion | Biofuel & Bio-based Product Development |
CCS/BECCS | Biomimicry Catalyst | Thermochemical Conversion
Program Studi Teknik Kimia, Teknik Pangan, Teknik Bioenergi dan Kemurgi, Institut Teknologi Bandung 74