6
Matlab: Nonlinear Algebraic Systems 1. Nonlinear algebraic equation solvers 2. Exothermic chemical reactor example

nonlinear

Embed Size (px)

DESCRIPTION

nonliner

Citation preview

Page 1: nonlinear

Matlab: Nonlinear Algebraic Systems

1. Nonlinear algebraic equation solvers

2. Exothermic chemical reactor example

Page 2: nonlinear

Matlab: Nonlinear Algebraic Equations

fzero – scalar nonlinear equation solver» Syntax: x = fzero(‘fun’,xo)

– ‘fun’ is the name of the user provided Matlab m-file function (fun.m) that evaluates and returns the LHS of f(x) = 0

– xo is an initial guess for the solution of f(x) = 0

– Discussed last lecture

fsolve – multivariable nonlinear equation solver» Function for solving system of nonlinear algebraic

equations

» Syntax: x = fsolve(‘fun’,xo)– Same syntax as fzero, but x is a vector of variables and the function,

‘fun’, returns a vector of equation values, f(x)

» Part of the Matlab Optimization toolbox

» Multiple algorithms available in options settings (e.g. trust-region dogleg, Gauss-Newton, Levenberg-Marquardt)

Page 3: nonlinear

Exothermic Chemical Reactor Example

Steady-state model

Parameter values» k0 = 3.493x107 h-1, E = 11843 kcal/kmol

» (-H) = 5960 kcal/kmol, Cp = 500 kcal/m3/K

» UA = 150 kcal/h/K, R = 1.987 kcal/kmol/K

» V = 1 m3, q =1 m3/h,

» CAf = 10 kmol/m3, Tf = 298 K, Tj = 298 K.

Problem» Find all steady-state points:

0

0

0 ( ) exp( / )

0 ( ) ( ) exp( / ) ( )Af A A

p f A j

q C C Vk E RT C

qC T T H Vk E RT C UA T T

),( TCA

Page 4: nonlinear

x = fsolve('cstr',xo,options) 'cstr' – name of the Matlab m-file function (cstr.m) for

the CSTR model xo – initial guess of steady-state solution: xo = [CA T] ' options – Matlab structure of optimization parameter

values created with the optimset function

Example usage

>> xo = [10 300]';

>> x = fsolve('cstr',xo,optimset('Display','iter'))

Solution of CSTR Model with fsolve

Page 5: nonlinear

Create m-file cstr.m

function f = cstr(x)

ko = 3.493e7;E = 11843;H = -5960;rhoCp = 500;UA = 150;R = 1.987;V = 1;q = 1;Caf = 10;Tf = 298;Tj = 298;

Ca = x(1);T = x(2);

f(1) = q*(Caf - Ca) - V*ko*exp(-E/R/T)*Ca;f(2) = rhoCp*q*(Tf - T) + -H*V*ko*exp(-E/R/T)*Ca + UA*(Tj-T);

f=f';

Page 6: nonlinear

Single Steady-State Solution

>> xo = [10 300]';>> x = fsolve('cstr',xo,optimset('Display','iter'))

Norm of First-order Trust-region Iteration Func-count f(x) step optimality radius 0 3 1.29531e+007 1.76e+006 1 1 6 8.99169e+006 1 1.52e+006 1 2 9 1.91379e+006 2.5 7.71e+005 2.5 3 12 574729 6.25 6.2e+005 6.25 4 15 5605.19 2.90576 7.34e+004 6.25 5 18 0.602702 0.317716 776 7.26 6 21 7.59906e-009 0.00336439 0.0871 7.26 7 24 2.98612e-022 3.77868e-007 1.73e-008 7.26Optimization terminated: first-order optimality is less than options.TolFun.

x =

8.5637 311.1702