Page 109 - Numerical Methods for Chemical Engineering
P. 109
98 2 Nonlinear algebraic systems
search bifurcation.m searches for a bifurcation point along a user-defined linear path in
parameter space
(2.159)
Θ(λ) = (1 − λ)Θ 0 + λΘ 1
The program is invoked for the simple quadratic example above by
a=1; % initial lambda value to try as initial guess
b=0; % final lambda value to try as initial guess
num lambda = 10; % # of lambda values to try as initial guess
theta 0=0; % parameter value at lambda = 0
theta 1=4; % parameter value at lambda = 1
x0 = -1.1; % initial guess of solution
fun name = ‘calc f quad’;
[x b,theta b,lambda b,ifound b] = search bifurcation(fun name, . . .
theta 0,theta 1,a,b,x0,num lambda),
where the routine for the function vector of the nonlinear system is
function f = calc f quad(x,theta);
f = x.ˆ2 + theta.*x + 1;
return;
MATLAB summary
The main routine for solving nonlinear algebraic systems f (x) = 0 is fsolve,
x = fsolve(fun name, x0, Options, P1, P2,...);
fun name is the name of a routine,
function f = fun name(x, P1, P2,...);
that returns the function vector for input x for the system under consideration. x0 is the
initial guess, and P1, P2, . . . are optional model parameters. Options is a data structure
managed by optimset that controls the operation of fsolve, e.g.
Options = optimset(‘LargeScale’, ‘off’, ‘Display’, ‘off’);
If the Jacobian matrix can be computed analytically, we use
Options = optimset(Options, ‘Jacobian’, ‘on’);
and return the Jacobian as a second argument,
function [f, Jac] = fun name(x, P1, P2,...);
Other options that will be found to be useful in Chapter 6 are
Options = optimset(Options,’ JacobPattern’, S);
and
Options = optimset(Options, ‘JacobMult’, Jfun name);