0% found this document useful (0 votes)
6 views3 pages

Labwork 5

The document outlines exercises related to linear programming and numerical methods using Matlab. It includes formulating a linear programming problem for a gas-processing plant, estimating integrals using various Matlab functions, and performing numerical differentiation. Additionally, it provides specific tasks for implementing these methods in Matlab.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Labwork 5

The document outlines exercises related to linear programming and numerical methods using Matlab. It includes formulating a linear programming problem for a gas-processing plant, estimating integrals using various Matlab functions, and performing numerical differentiation. Additionally, it provides specific tasks for implementing these methods in Matlab.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Labwork 5

Linear programming
Exercise 1
Suppose that a gas-processing plant receives a fixed amount of raw gas each week. The raw
gas is processed into two grades of heating gas, regular and premium quality. These grades of
gas are in high demand (that is, they are guaranteed to sell) and yield different profits to the
company. However, their production involves both time and on-site storage constraints. For
example, only one of the grades can be produced at a time, and the facility is open for only 80
hr/week. Further, there is limited on-site storage for each of the products. All these factors are
listed below (note that a metric ton, or tonne, is equal to 1000 kg):

a. Develop a linear programming formulation to maximize the profits for this operation.
b. Minimization of the problem above using function: linprog in Matlab
c. Demonstrate the feasible solution space using the graphical solution of a linear
programming problem.
Hint: use linspace and meshgrid and plot

Numerical Integration
Exercise 2

a. Use Matlab trapz function to estimate the integral above from 0 to 0.8
b. Use the trapezoidal function in Matlab, cumtrapz. Compare the difference between
two functions
c. Use the simpson function in Matlab, quad
d. Use the quadrature function
function q = quadadapt(f,a,b,tol,varargin)
% Evaluates definite integral of f(x) from a to b
if nargin < 4 || isempty(tol),tol = 1.e-6;end
c = (a + b)/2;
fa = feval(f,a,varargin{:});
fc = feval(f,c,varargin{:});
fb = feval(f,b,varargin{:});
q = quadstep(f, a, b, tol, fa, fc, fb, varargin{:});
end
function q = quadstep(f,a,b,tol,fa,fc,fb,varargin)
% Recursive subfunction used by quadadapt.
h = b - a; c = (a + b)/2;
fd = feval(f,(a+c)/2,varargin{:});
fe = feval(f,(c+b)/2,varargin{:});
q1 = h/6 * (fa + 4*fc + fb);
q2 = h/12 * (fa + 4*fd + 2*fc + 4*fe + fb);
if abs(q2 - q1) <= tol
q = q2 + (q2 - q1)/15;
else
qa = quadstep(f, a, c, tol, fa, fd, fc, varargin{:});
qb = quadstep(f, c, b, tol, fc, fe, fb, varargin{:});
q = qa + qb;
end
end

Exercise 3
a. Define the following function using syms:

Compute the integral, and the first and second derivatives of the above function
symbolically
b. Define the following function using syms:

Compute the integral with respect to x and second derivative with respect to z

Numerical differentiation
Exercise 4

a. Use Matlab diff function to differentiate the function f(x) from


b. Comparison of the exact derivative with numerical estimates
c. Use forward function
% y = vector containing function values
% x = vector containing increments
% p = point number where to calculate
% d = derivative of y at point p
function d = forward(y,x,p)
d = (y(p+1)-y(p))/(x(p+1)-x(p));
end
d. Use backward function
function d = backward(y,x,p)
d = (y(p)-y(p-1))/(x(p)-x(p-1));
end
e. Use central function
function d = central(y,x,p)
d = (y(p+1)-y(p-1))/(x(p+1)-x(p-1));
end

You might also like