<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mintoc.de/index.php?action=history&amp;feed=atom&amp;title=Batch_reactor_%28GEKKO%29</id>
	<title>Batch reactor (GEKKO) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mintoc.de/index.php?action=history&amp;feed=atom&amp;title=Batch_reactor_%28GEKKO%29"/>
	<link rel="alternate" type="text/html" href="https://mintoc.de/index.php?title=Batch_reactor_(GEKKO)&amp;action=history"/>
	<updated>2026-06-09T08:06:31Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://mintoc.de/index.php?title=Batch_reactor_(GEKKO)&amp;diff=2288&amp;oldid=prev</id>
		<title>JohnHedengren: Add gekko solution for batch reactor.</title>
		<link rel="alternate" type="text/html" href="https://mintoc.de/index.php?title=Batch_reactor_(GEKKO)&amp;diff=2288&amp;oldid=prev"/>
		<updated>2019-04-11T13:49:07Z</updated>

		<summary type="html">&lt;p&gt;Add gekko solution for batch reactor.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This page contains a solution of the [[Batch reactor]] problem in [https://gekko.readthedocs.io/en/latest/ GEKKO] Python format. The model in Python code for a fixed control discretization grid uses orthogonal collocation and a simultaneous optimization method. The GEKKO package is available with &amp;#039;&amp;#039;&amp;#039;pip install gekko&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;Python&amp;quot;&amp;gt;&lt;br /&gt;
import numpy as np&lt;br /&gt;
import matplotlib.pyplot as plt&lt;br /&gt;
from gekko import GEKKO&lt;br /&gt;
&lt;br /&gt;
m = GEKKO()&lt;br /&gt;
&lt;br /&gt;
nt = 501&lt;br /&gt;
m.time = np.linspace(0,1,nt)&lt;br /&gt;
&lt;br /&gt;
# Variables&lt;br /&gt;
x1 = m.Var(value=1)&lt;br /&gt;
x2 = m.Var(value=0)&lt;br /&gt;
T = m.MV(value=398,lb=298,ub=398)&lt;br /&gt;
T.STATUS = 1&lt;br /&gt;
T.DCOST = 1e-6&lt;br /&gt;
k1 = m.Intermediate(4000*m.exp(-2500/T))&lt;br /&gt;
k2 = m.Intermediate(6.2e5*m.exp(-5000/T))&lt;br /&gt;
&lt;br /&gt;
p = np.zeros(nt)&lt;br /&gt;
p[-1] = 1.0&lt;br /&gt;
final = m.Param(value=p)&lt;br /&gt;
&lt;br /&gt;
# Equations&lt;br /&gt;
m.Equation(x1.dt()==-k1*x1**2)&lt;br /&gt;
m.Equation(x2.dt()==k1*x1**2 - k2*x2)&lt;br /&gt;
&lt;br /&gt;
# Objective Function&lt;br /&gt;
# maximize final x2&lt;br /&gt;
m.Obj(-x2*final)&lt;br /&gt;
&lt;br /&gt;
m.options.IMODE = 6&lt;br /&gt;
m.options.NODES = 3&lt;br /&gt;
m.solve()&lt;br /&gt;
&lt;br /&gt;
print(&amp;#039;Optimal x2(tf): &amp;#039; + str(x2.value[-1]))&lt;br /&gt;
&lt;br /&gt;
plt.figure(1)&lt;br /&gt;
plt.subplot(2,1,1)&lt;br /&gt;
plt.plot(m.time,x1.value,&amp;#039;k:&amp;#039;,\&lt;br /&gt;
         LineWidth=2,label=r&amp;#039;$x_1$&amp;#039;)&lt;br /&gt;
plt.plot(m.time,x2.value,&amp;#039;b-&amp;#039;,\&lt;br /&gt;
         LineWidth=2,label=r&amp;#039;$x_2$&amp;#039;)&lt;br /&gt;
plt.plot(m.time[-1],x2.value[-1],&amp;#039;o&amp;#039;,\&lt;br /&gt;
         color=&amp;#039;orange&amp;#039;,MarkerSize=5,\&lt;br /&gt;
         label=r&amp;#039;$x_2\left(t_f\right)$&amp;#039;)&lt;br /&gt;
plt.legend()&lt;br /&gt;
plt.ylabel(&amp;#039;Mole Fraction&amp;#039;)&lt;br /&gt;
plt.subplot(2,1,2)&lt;br /&gt;
plt.plot(m.time,T.value,&amp;#039;r--&amp;#039;,\&lt;br /&gt;
         LineWidth=2,label=&amp;#039;Temperature&amp;#039;)&lt;br /&gt;
plt.ylabel(r&amp;#039;$T/;(^oC)$&amp;#039;)&lt;br /&gt;
plt.legend(loc=&amp;#039;best&amp;#039;)&lt;br /&gt;
plt.xlabel(&amp;#039;Time&amp;#039;)&lt;br /&gt;
plt.ylabel(&amp;#039;Value&amp;#039;)&lt;br /&gt;
plt.show()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A solution is calculated with an objective function value of x2(tf) = 0.6108.&lt;br /&gt;
&lt;br /&gt;
[[File:Batch_reactor_GEKKO.png]]&lt;br /&gt;
 &lt;br /&gt;
[[Category:Gekko]]&lt;/div&gt;</summary>
		<author><name>JohnHedengren</name></author>
	</entry>
</feed>