Вы находитесь на странице: 1из 37

ORTHOGONAL

COLLOCATION
METHOD
OUTLINE
Introduction
Aim and objectives
Method of weighted residues
Collocation methods
Orthogonal collocation
Legendre polynomials method
Jacobi polynomials method
Orthogonal representation of differential equations
Solved example
Conclusion
Appendix: MATLAB programme
Reference
Introduction
Orthogonal collocation is a numerical method
that handles ordinary differential equations of
boundary value type.
Examples of such problems include:
Conditions at the two ends of a fixed bed
reactor
Conditions at the two sides of a membrane
This method is particularly attractive for
solving nonlinear problems which have defied
analytical treatment.
Introduction (Contd)
Orthogonal
Collocation
collocation
Method
method

Subdomain
Method

Methods of
Least Square
Weighted
Method
Residuals

Moment
Method

Galerkin

Figure 1: Various methods of weighted


residuals
Aim and Objectives
Study the principle of orthogonal collocation.
Use the method of orthogonal collocation to
solve a nonlinear problem.
Method of weighted residuals
Given a problem of the form:
DE: (1)
BC:
You construct an approximate solution of the
problem; the approximate solution has the
form:

Trial function
Method of weighted residuals
(Contd)
You substitute the trial function into the
differential equation to form the Residue:

Define the inner product using the residue:

We aim to minimise the residual by setting


the inner product to be zero:
0.(5)
Collocation methods
In the collocation method, the test function is
defined as the Dirac delta function at N
interior points (collocation points) over the
interval. The Dirac delta function is given by:

The Dirac delta function has the property:


Orthogonal collocation
This method provides a mechanism for
automatically picking the collocation points as
roots of orthogonal polynomials. This method
chooses the trial function to be the linear
combination:

The basic property of an orthogonal polynomial


Pn(x) is:
Orthogonal collocation (Contd)
The orthogonal collocation method uses:
1. Legendre polynomials to solve unsymmetrical
problems. Legendre polynomials have the general
form:

2. Jacobi polynomials to solve symmetrical problems.


Jacobi polynomials have the general form:

, > -1 are parameters characterising the


polynomials
Note: Both polynomials are defined over the interval[-
1, 1]
Legendre polynomials
method
Using the Legendre polynomials method, The
coefficients ai in equation (8) can be written
for the (n + 2) points (z0 to zn+1) as

z is calculated from the transformation equation


Jacobi polynomials
method
Using the Jacobi polynomials method, The
coefficients ai in equation (8) can be written
for the (n + 2) points (z0 to zn+1) as

z is same as in equation (13)


Orthogonal collocation representation
of differential equations

Equations (12) and (14) can be expressed in
terms of unknown vector of coefficients d as:

Where Q is a known matrix and is given in


terms of the known collocation point zj raised to
an appropriate collocation order, i.
In the Legendre method,

In the Jacobi method,


Orthogonal collocation representation
of differential equations (Contd)
The first derivatives of equations (16) and
(17) yield:
Orthogonal collocation representation
of differential equations (Contd)
Equations
(18) and (19) can be written in the compressed
form:

In the Legendre method,

In the Jacobi method,

From equation (15),

This implies:

Equation (20) can be re-written as:


Orthogonal collocation representation
of differential equations (Contd)
In a similar fashion the orthogonal collocation
form of a second order differential equation
can be written as:

Where:

Which can be written as:


Table 1: Values of A and B matrices for N=1
and N=2 for Legendre polynomial (From
Ramirez, 1998, pg. 417)
Table 2: Values of A and B matrices for N=1 and N=2 for
Jacobi polynomial for the three applicable geometries (From
Ramirez, 1998, pg. 421)
Planar Geometry (a = 1)

n=1

n=2

Cylindrical Geometry (a = 2)

n=1

n=2

Spherical Geometry (a = 3)

n=1

n
n==2
2
Solved example
Apply the orthogonal collocation method to solve the two-point

boundary value problem arising from the application of the maximum

principle of Pontryagin to a batch penicillin fermentation. Obtain the

solution of this problem, and show the profiles of the state variables,

the adjoint variables, and the optimal temperature. The equations

that describe the state of the system in a batch penicillin

fermentation are:
Cell mass production

Penicillin synthesis

Where y1 = dimensionless concentration of cell mass


y2 = dimensionless concentration of penicillin
t = dimensionless time, 0 t 1.
Solved example (Contd)
parameters bi are functions of temperature, :
The

Where w1 = 13.1 (value of b1 at 25oC obtained


from fitting the model to experimental data)
w2 = 0.005
w3 = 30oC
w4 = 0.94 (value of b2 at 25oC)
w5 = 17.1 (value of b3 at 25oC)
w6 = 20oC
= temperature, oC.
Solved example (Contd)
adjoint equations:
The

The Hamiltonian:

The necessary condition for maximum:

Equations (27) to (31) form a two-point boundary-


value problem. We will apply the orthogonal
collocation method to obtain the solution of this
problem, and show the profiles of the state
variables, the adjoint variables, and the optimal
temperature
Results
Number of internal collocation points = 10
Relaxation factor = 0.9
Integrating. Please wait.
Iteration 1
Iteration 2
Iteration 3
Iteration 4
Iteration 5
Iteration 6
Iteration 7
Iteration 8
Iteration 9
Iteration 10
Iteration 11
Results (Contd)
A=

-111.0000 123.3257 -16.1530 5.6279 -2.8743 1.8269 -1.3534 1.1362 -1.0743 1.1687 -1.6303
1.0000
-47.6368 37.8172 12.4459 -3.8077 1.8726 -1.1713 0.8607 -0.7192 0.6782 -0.7366 1.0268
-0.6297
13.6003 -27.1288 6.8747 8.9175 -3.4619 1.9922 -1.4072 1.1509 -1.0719 1.1560 -1.6057
0.9840
-6.9153 12.1125 -13.0140 2.5238 7.3381 -3.2488 2.0809 -1.6223 1.4719 -1.5643 2.1575
-1.3201
4.3348 -7.3113 6.2008 -9.0065 1.0673 6.7114 -3.2794 2.3074 -1.9911 2.0614 -2.8081 1.7135
-3.0224 5.0169 -3.9145 4.3743 -7.3624 0.3045 6.7171 -3.5976 2.8018 -2.7650 3.6865 -2.2391
2.2391 -3.6865 2.7650 -2.8018 3.5976 -6.7171 -0.3045 7.3624 -4.3743 3.9145 -5.0169 3.0224
-1.7135 2.8081 -2.0614 1.9911 -2.3074 3.2794 -6.7114 -1.0673 9.0065 -6.2008 7.3113 -4.3348
1.3201 -2.1575 1.5643 -1.4719 1.6223 -2.0809 3.2488 -7.3381 -2.5238 13.0140 -12.1125
6.9153
-0.9840 1.6057 -1.1560 1.0719 -1.1509 1.4072 -1.9922 3.4619 -8.9175 -6.8747 27.1288
-13.6003
0.6297 -1.0268 0.7366 -0.6782 0.7192 -0.8607 1.1713 -1.8726 3.8077 -12.4459 -37.8172
47.6368
-1.0000 1.6303 -1.1687 1.0743 -1.1362 1.3534 -1.8269 2.8743 -5.6279 16.1530 -123.3257
111.0000
Results (Contd)
(a) (b)
1 1.5

Penicillin
Cell

0.5 0.5

0 -0.5
0 0.5 1 0 0.5 1
Time Time
(c) (d)
4 30

Temperature (deg C)
3
First Adjoint

2 25

0 20
0 0.5 1 0 0.5 1
Time Time
Figure 2: Plots from results of MATLAB
programme
Conclusion
Orthogonal collocation method does not need
all the values to solve the problem only the
collocation points are required.
After the values at the collocation points are
obtained, the value at any other point can be
determined.
Orthogonal collocation is relatively easier
when compared to other methods.
The efficiency is also good only second to the
Galerkin method which is more rigorous.
Appendix: MATLAB Programme
Matlab programme: guess=3;
% This program calculates and plots % Define M-file containing the set of
% the concentration of cell mass, concentration differential equations
of penicillin,
fname = 'example_equations';
% optimal temperature profile, and adjoint
%Define M-file containing the necessary
variable of a batch
condition function
% penicillin fermentor. It uses the function
COLLOCATION to fth = 'example_theta';
% solve the set of system and adjoint % Input data
equations. n = input(' Number of internal collocation
function example points = ');
clear all rho= input(' Relaxation factor = ');
clc % Solution of the set of differential equations
% Define known parameters [t,y] =
w=[13.1, 0.005, 30, 0.94, 1.71, 20]; collocation(fname,0,1,y0,yf,guess,n,rho,
% Initial guess [],w,fth);
y0=[0.03,0]; % Temperature changes
% Vector of final conditions for k = 1:n+2
yf=0; theta(k) = fzero(fth,30,1e-6,y(:,k),w);
% Vector of guessed initial conditions
end
Appendix: MATLAB % This function introduces the set of

Programme ordinary differential


% equations.
% Temperature
theta = fzero(example_theta,30,1e-6,y,w);
% Calculating the b's
% Plotting the results
b1 = w(1) * (1-w(2)*(theta-w(3))^2) / (1-
subplot(2,2,1), plot(t,y(1, :))
w(2)*(25-w(3))^2);
xlabel ( 'Time')
if b1<0, b1=0; end
ylabel ( 'Cell' )
b2 = w(4) * (1-w(2)*(theta-w(3))^2) / (1-
title(' (a) ' ) w(2)*(25-w(3))^2);
subplot(2,2,2), plot(t,y(2, :)) if b2<0, b2=1e-6; end
xlabel ( 'Time') b3 = w(5) * (1-w(2)*(theta-w(6))^2) / (1-
ylabel('Penicillin') w(2)*(25-w(6))^2);
title( ' (b) ' ) if b3<0, b3=0; end
subplot(2,2,3), plot(t,y(3,: ) ) % Evaluating the function values
xlabel ( 'Time' ) f (1) = b1*y(1) - b1/b2*y(1)^2;
ylabel ( 'First Adjoint' ) f (2) = b3*y(1);
title(' (c) ') f (3) = -b1*y(3) + 2*b1/b2*y(1)*y(3) - b3;
subplot(2,2,4), plot(t,theta) f = f'; % Make it a column vector
xlabel('Time') end
ylabel('Temperature (deg C) ')
title ( ' (d)' )
function f =
example_equations(t,y,w,example_theta)
Appendix: MATLAB
Programme
function ftheta =
example_theta(theta,y,w)
% This function calculates the value of the
necessary condition
% as a function of the temperature
(theta).
% Calculating the b's
b1 = w(1) * (1-w(2)*(theta-w(3))^2) / (1- % The function
w(2)*(25-w(3))^2); ftheta = y(3)*(y(1)*db1-y(1)^2*(db1*b2-
db1 = w(1)*(-w(2))*2*(theta-w(3) )/ (1- db2*b1)/b2^2)+y(1)*db3;
w(2)*(25-w(3))^2); end
b2=w(4)*(1-w(2)*(theta-w(3))^2)/(1-
w(2)*(25-w(3))^2); function [x,y] =
db2=w(4)*(-w(2))*2*(theta-w(3))/(1- collocation(ODEfile,x0,xf,y0,yf,guess,n,rho,...
w(2)*(25-w(3))^2); tol, varargin)
b3=w(5)*(1-w(2)*(theta-w(6))^2)/(1- %COLLOCATION Solves a boundary value set
w(2)*(25-w(6))^2); of ordinary differential
db3=w(5)*(-w(2))*2*(theta-w(6))/(1- % equations by the orthogonal collocation
w(2)*(25-w(6))^2); method.
Appendix: MATLAB
Programme % the function F. Pass an empty matrix for
% RHO or TOL to use the
[X,Y]=COLLOCATION('F',X0,XF,Y0,YF,GAMM % default value.
A,N) integrates the set of %
% ordinary differential equations from X0 % See also SHOOTING
to XF by the Nth-degree
% (c) N. Mostoufi & A. Constantinides
% orthogonal collocation method. The
% January 1, 1999
equations are contained in
% Initialization
% the M-file F.M. Y0, YF, and GAMMA are
the vectors of initial if nargin < 7 | isempty(n)
% conditions, final conditions, and starting n = 1;
guesses respectively. end
% The function returns the independent if nargin < 8 | isempty(rho)
variable in the vector X rho = 1;
% and the set of dependent variables in end
the matrix Y. if nargin < 9 | isempty(tol)
tol = 1e-6;
% end
[X,Y]=COLLOCATION('F',X0,XF,Y0,YF,GAMM y0 = (y0(:).')'; % Make sure it's a column
A,N,RHO,TOL,P1,P2,...) vector
% uses relaxation factor RHO and
tolerance TOL for convergence
Appendix: MATLAB
Programme % Coefficients of the Legendre polynomial
for k = 0 : n/2
cl(2*k+1) = (-1)^k * gamma(2*n-2*k+1) / ...
yf = (yf(:).')'; % Make sure it's a column
vector (2^n * gamma(k+1) * gamma(n-k+1) *
gamma(n-2*k+1));
guess = (guess(:).')'; % Make sure it's a
column vector if k < n/2
% Checking the number of guesses cl(2*k+2) = 0;
if length(yf) ~= length(guess) end
error(' The number of guessed conditions end
is not equal to the number of final zl = roots (cl) ; % Roots of the Legendre
conditions.') polynomial
end z = [-1; sort(zl); 1]; % Collocation points (z)
r = length(y0); % Number of initial x = (xf-x0)*z/2+(x0+xf)/2; % Collocation
conditions points (x)
m = r + length(yf); % Number of boundary % Bulding the vector of starting values of
conditions the dependent variables
% Checking the number of equations [p,q] = RK(ODEfile,x0,xf,( xf-x0)/ 20,[ y0 ;
ftest = feval(ODEfile,x0,[y0 ; guess],2 ,varargin{:}) ;
guess],varargin{:}); for k = 1:m
if length(ftest) ~= m y(k, :) = spline(p,q(k, :),x');
error(' The number of equations is not end
equal to the number of boundary
conditions.')
Appendix: MATLAB
Programme iter = 0;
maxiter = 100;
y(r+1:m,end) = yf(1:m-r); F = zeros (m* (n+2),1) ;
% Building the matrix A Fa = zeros (m*( n+2),1 );
Q(:,1)= ones(n+2,1); dY = zeros (m*( n+2),1 ) ;
C(:, 1)= zeros (n+2,1); position = []; % Collocation points excluding
for i = 1:n+1 boundary conditions
Q(:,i+1) = x.^i; for k = 1:m
C(:,i+1) = i*x.^(i-1); if k <= r
end position = [position, (k-1)* (n+2)+[2:n+2] ] ;
A = C*inv(Q); else
for k = 1:m position = [position, (k-1)* (n+2)+
k1 = (k-1)*(n+2)+1; [1:n+1] ] ;
k2 = k1 + n+1; end
Am(k1:k2,k1:k2) = A; % Building the end
matrix Am % Newton's method
Y(k1:k2) = y(k,:); % Building the vector Y while max(abs(Y1 - Y)) > tol & iter < maxiter
End iter = iter + 1;
Y = Y'; % Make it a column vector fprintf(' Iteration %3d\n',iter)
Y1 = Y * 1.1; Y1 = Y;
Appendix: MATLAB
Programme
% Building the vector F Fa(kkk : n+2 : (m-1)* (n+2)+kkk) = ...
for k = 1:n+2 feval(ODEfile,x(kkk),a(kkk:n+2:(m-
F(k : n+ 2 : (m-1)* (n+2)+k) = 1)*(n+2)+kkk),varargin{:});
feval(ODEfile,x(k),... end
Y (k : n+2 : (m-1)* (n+2)+ k), varargin{ :}) ; fnka = Am * a - Fa;
end jacob(: ,nc) = (fnka(position) - fnk(position)) ...
fnk =Am * Y - F; / dY(position(nc)) ;
% Set dY for derivation
end
for k = 1:m*(n+1)
end
if Y(position(k)) ~= 0
% Next approximation of the roots
dY(position(k)) = Y(position(k)) / 100;
if det(jacob) == 0
else
dY(position(k)) = 0.01; Y(position) = Y(position) +
max([abs(dY(position)); 1.1*tol]);
end
end
else
% Calculation of the Jacobian matrix Y(position)=Y(position) - rho * inv(jacob) *
fnk(position);
for k = 1:m
for kk = 1:n+1 end
a = Y; end
nc = (k-1)*(n+1)+ kk; % Rearranging the y's
a(position(nc) ) = Y (position(nc)) + for k = 1:m
dY(position(nc));
for kkk = 1:n+2
Appendix: MATLAB % empty matrix, the 2nd-order Runge-Kutta

Programme method will be


% performed.
%
% [X,Y]=RK('F',XI,XF,H,YI,N,P1,P2,...) allows
for additional
k1 = (k-1)*(n+2)+1;
k2 = k1 + n+1;
% arguments which are passed to the
y(k, :) = Y(k1:k2)';
function F(X,P1,P2,...).
end %
x = x'; % See also ODE23, ODE45, ODE113,
if iter >= maxiter ODE15S, ODE23S, EULER, MEULER,
disp('Warning : Maximum iterations reached.') % ADAMS, ADAMSMOULTON
end % (c) N. Mostoufi & A. Constantinides
end
% January 1, 1999

function [x,y]=RK(ODEfile,xi,xf,h,yi,n,varargin)
% Initialization
% RK solves a set of ordinary differential if isempty (h) | h == 0
equations by the h = linspace (xi,xf ) ;
% Runge-Kutta method. end
%
if nargin == 5 | isempty(n) | n < 2 | n > 5
% [X,Y]=RK('F',XI,XF,H,YI,N) solves a set of
ordinary differential n = 2;
% equations by the Nth-order Runge-Kutta end
method, from XI to XF.
% The equations are given in the M-file F.M. H is
hte length of interval.
% YI is the vector of initial values of hte
dependent
Appendix: MATLAB
Programme
n = fix (n) ; case 3 % 3rd-order Runge-Kutta
yi = (yi(:).')'; % Make sure it's a column for i = 1:length(x)-1
vector k1 = d(i) * feval(ODEfile,x(i), y(:,i),varargin{:});
x = [xi:h:xf]; % Vector of x values k2 = d(i) * feval(ODEfile,x(i)+d(i)/2,y(:,i)+k1/2,...
if x(end) ~= xf varargin{:}) ;
k3 = d(i) * feval(ODEfile,x(i+1),y(:,i)+2*k2-
x(end+1) = xf;
k1,varargin{:});
end y(:,i+1) = y(:,i) + (k1+4*k2+k3)/6;
d = diff(x); % Vector of x-increments end
y(:,1) = yi; % Initial condition case 4 % 4th-order Runge-Kutta
% Solution for i = 1:length(x)-1
switch n k1 = d(i) * feval(ODEfile,x(i),y(:,i),varargin{:});
case 2 % 2nd-order Runge-Kutta k2 = d(i) * feval(ODEfile,x(i)+d(i)/2,y(:,i)+k1/2,...
varargin{:});
for i = 1:length(x)-1
k3 = d(i) * feval(ODEfile,x(i)+d(i)/2,y(:,i)+k2/2,...
k1 = d(i) *
varargin{:});
feval(ODEfile,x(i),y(:,i),varargin{:});
k4 = d(i) * feval(ODEfile,x(i+1),y(:,i)
k2 = d(i) * feval(ODEfile,x(i+1),y(:,i) +k3,varargin{:});
+k1,varargin{:}); y(:,i+1) = y(: ,i) + (k1+2*k2+2*k3+k4)/6;
y(:,i+1) = y(:,i) + (k1+k2)/2; end
end
Appendix: MATLAB
Programme
case 5 % 5th-order Runge-Kutta
for i = 1:length(x)-1
k1 = d(i) * feval(ODEfile,x(i), y(:,i),
varargin{:});
k2 = d(i) * feval(ODEfile,x(i)+d(i)/2,y(:,i)+
k1/2,...
varargin{:});
k3 = d(i) * feval(ODEfile,x(i)+d(i)/4,y(:,i)
+3*k1/16+k2/16,...
varargin{:});
k4 = d(i) * feval(ODEfile,x(i)+d(i)/2,y(:,i)
+k3/2,...
varargin{:});
k5 = d(i) * feval(ODEfile,x(i)
+3*d(i)/4,y(:,i )-3*k2/16+...
6*k3/16+9*k4/16, varargin{:});
k6 = d(i) * feval(ODEfile,x(i+1), y(:, i)
+k1/7+4*k2/7+...
6*k3/7-12*k4/7+8*k5/7, varargin{:});
y(:, i+1) = y(: ,i) +
(7*k1+32*k3+12*k4+32*k5+7*k6)/90;
end
end
References
Collocation and Orthogonal Collocation (no date).Retrieved October28, 2014
from: http://faculty.washington.edu/finlayso/ebook/bvp/OC/OC_unsym.htm
Constantinides, Alkis and Mostoufi, Navid (1999).Numerical Methods for
Chemical Engineers with MATLAB Applications. New Jersey: Prentice Hall PTR
Fletcher, C. A. J., (1984). Computational Galerkin Methods. New York:
Springer-Verlag.
Michelsen, M. L., and J. Villadsen, (1980). "Polynomial Solution of Differential
Equations," Proceedings of the First Conference on Computer Aided Process
Design held at Henniker, New Hampshire.
Ramirez, Fred W. (1998).Computational Methods in Process Simulation. New
York: Elsevier Science & Technology Books.
Villadsen, J., and M. L. Michelsen (1978). Solution of Differential Equation
Models by Polynomial Approximation. New Jersey: Prentice Hall, Engelwood
Cliffs.
Villadsen, J., Selected (1970). Approximation Methods for Chemical
Engineering Problems. Copenhagen: Reproset
THANK
YOU