# Reactor Optimization with fmincon!

MIT 10.37 students and other chemical engineers in reactor enegineering might find this post interesting. Here I’m going to talk about how to apply `fmincon`

to typical reactor engineering optimization problems.

### Basic `fmincon`

usage

Consider the optimization problem below,

it only takes three steps to translate into matlab code as shown below.

There’s an alternative way of translating constraints, instead of using `A`

, `b`

, `Aeq`

, `beq`

, `lb`

, and `ub`

, we can use `c`

and `ceq`

.

Matlab tutorial has well covered typical ways of using `fmincon`

to perform optimization. Please check it out if you want to know more.

### Reactor optimization example

Now with the basic knowledge of using `fmincon`

, let’s apply it to our reactor design domain. A good example is 2016-02-22’s 10.37 recitation problem. It has a typical reaction pathway where reactant goes to desired product, which however will react to form an undesired product. As chemical engineers, we should manipulate knobs, e.g., temperature, residence time, etc., in order to maximize molar yiled of desired product.

#### Define objective function

As we discussed, here we want to maximize molar yield of `D`

(diglyceride) by tuning (temperature), , , and . Putting it into mathematic term would be

Translating it to matlab, we can define in below:

#### Set up constraints

Almost all the real-life chemical engineering optimization problems have certain number of constraints. They are usually from `mass balance`

, `kinetics rules`

, `physical bounds`

, etc.

- Mass balance

For convenience, we assume volumetric flowrate is not changed from inlet to outlet. so we have the following equations for major species’ mass balance in CSTR.

- Kinetics rules

Kinetics coefficient `k`

has temperature dependence according to Arrhenius law.

- Physical bounds

Physical bounds are those constraints that seem obvious to you but can largely reduce the search space for Matlab. So in order to get correct answer more quickly, we should provide as much extra information of physics as possible.

For instance, the concentrations and residence time can not be negative, and temperature should always be grater than 273 K (otherwise frozen). Here we will add another constraint where temperature cannot go beyound 350 C because of heating power limitation.

In summary we have,

Put all these constraints together in Matlab using `c`

and `ceq`

,

#### call `fmincon`

to optimize

Simply run the optimization by calling `fmincon`

and feeding `objFun`

and `allcon`

we defined early.

Eventually you will have optimal yield of diglyceride to be 30%. You can find the Matlab codes here.