Building A MATLAB Graphical User Interface To Solv
Building A MATLAB Graphical User Interface To Solv
net/publication/325079801
CITATION READS
1 3,146
3 authors, including:
All content following this page was uploaded by Jianan Zhao on 05 December 2018.
Figure 5: Submission 1 main GUI screenshot with plot of the dependent variable T for the veri�cation case in Appendix A.
When the user modi�es an ODE, only one ODE from the list box
can be selected at one time. Also, items in the Initial Value(s)
list box can be selected; however, they are not related to any push
buttons. In a future version, a new GUI could be added to al-
low the user to edit initial values based on the selected line in
the Initial Value(s) list box independent of editing the corre-
sponding ODE.
3.2 Submission 2
3.2.1 Overview. Submission 2 goes beyond the scope of the
project requirements by allowing the user the capability to freely
edit equations in the GUI and to enter equations in any order
(Fig. 13). Allowing the text to be edited enables the user to wholesale
Figure 10: Submission 1 dialog box to select which variables copy text in order to share, save, and enter equations. Additionally,
to display on the plot. if an error is made in entering the equations into the dialog boxes,
the user can quickly �x it by editing the text directly. Furthermore,
if the user is comfortable, they can type their equations directly
without using the dialog boxes. This is very consistent with the
capabilities of POLYMATH.
At the heart of parsing the entered text is the use of regular is put at the bottom of the list of equations, and the column associ-
expressions. Regular expressions are useful for �nding speci�c se- ated with the variable is zeroed out. This process repeats until no
quences of text. Regular expressions make use of wildcards, white- changes occur in the matrix after an iteration.
space characters, alphanumeric ranges, and more to create a very If the matrix is not completely zeroed out, then any rows that are
powerful and �exible syntax for matching text. For example, in the not entirely zeros represent variables that are not properly de�ned,
GUI the left hand side of an ODE is in the form of d(y)/d(t), where and an error is returned to the user containing the variables that are
and t can be any variables. The regular expression ‘d\(\w*\)\/d\( improperly de�ned. If the entire matrix is zeroed out, then the list
\w*\)’ will match the left hand side of any correctly entered ODE. of equations recorded while zeroing out the matrix is the correct
The �rst step in parsing the equations is to break the equation order for the equations so that each equation is only dependent on
into two parts for the left- and right-hand sides. This is done by the previous equation.
searching for the ‘=’ character and taking either side as separate
strings. Of the two sides, the left-hand side is evaluated �rst. The 4 CONCLUSIONS
left-hand side of each equations has a speci�c structure–the exact The project assignment has been used for 21 total students across
form depends on if the equation is an algebraic equation, ODE, an two o�erings of the Applied Numerical Computing elective course
initial value, or the range of an independent variable. The structured at Oklahoma State University. The project has been challenging
left-hand side of each equation lends itself to being easily parsed and thought provoking for the students in the course without being
through regular expressions. unreasonable and overly time-consuming. Each student has typi-
The main concept used in parsing the right-hand side of an cally visited the instructor’s o�ce hours more than once over the
equation is to build a line of code by following order of operations one month time period allotted for the project. The instructor has
to identify the calculation to be done �rst, producing the code to o�ered assistance with debugging and brainstorming and imple-
evaluate the operation, and then abstracting the evaluated term menting approaches. The most challenging aspect of the project for
from the rest of the equation using a token. For example, the string most students is connecting the input from a subsidiary GUI win-
`x + y * z' becomes `x + #1', where #1 is placeholder for a dow back to the main GUI window. The submissions described here
structure containing the results of parsing `y * z'. Parsing the provide two di�erent methods for doing this, and the instructions
right-hand side becomes more complex when handling parentheses. and tips from the instructor in the assignment and in Fig. 4 suggest
The approach to handling parentheses is to replace the portion another alternative using .mat �les and cell arrays. Students are
of the equation inside of the parenthesis with a token and then encouraged to discuss ideas with their classmates, but the project
recursively calling theParseEq.m function with the replaced text. must be an individual e�ort. The vast majority of the students
The result is that for each nested level of parentheses, the function have earned an A on the project (all who started early enough to
is recursively called until the innermost level of parentheses is complete all of the required components, including the veri�cation
reached and evaluated normally. cases). The students have given the project a positive reception
as they can clearly see how it connects the prior course content
3.2.4 Equation Reordering. The problem of ordering the equa-
related to numerical solution of systems of ODEs and development
tions is reduced to a problem similar to Gaussian elimination. A
of GUIs for scienti�c applications. The project detailed in this paper
matrix is constructed where each row represents a dependent vari-
can be easily integrated into a variety of computational science and
able, and each column represents a unique variable needed to de�ne
engineering elective or required courses. The content is approach-
a variable. For each dependent variable, the element in the column
able for both senior undergraduates and graduate students from
of each variable needed to de�ne the dependent variable is set to 1.
a variety of disciplines given su�cient background in MATLAB
For example, the equations
programming and GUI design.
x =2 (1) Additional cases studies could be used to adapt the project to
other disciplines such as numerical methods, computational physics
= 3⇤x (2) or chemistry, mathematical biology, and other �elds of engineering.
These case studies could readily be developed from textbook ex-
z = 4⇤ +x (3) amples in these �elds or published modeling studies such as [1] in
yield the matrix (with columns and rows labeled for clarity) petrochemical manufacturing, [7] in computational pharmacology,
and [24] in mathematical biology.
x y
x 0 0
A VERIFICATION CASE
y 1 0
z 1 1 For the veri�cation case study, a system of ODEs is used as de�ned
and solved in an example in a chemical reaction engineering text-
Each dependent variable that is de�ned by an ODE has an asso-
book [4]. The equations describe the mass and energy balances for
ciated initial value previously de�ned. Therefore, all of the columns
a pair of gas-phase reactions that occur in a plug �ow reactor that
associated with variables de�ned in ODEs are zeroed out right
is operated non-isothermally:
after creating the matrix, representing the fact that the variable
is de�ned. Each dependent variable has exactly one equation in k1
A !B r 1A = k 1AC A (4)
which the variable will show up on the left hand side. When a row
k2 2
corresponding to a variable is zeroed out, the associated equation 2A !C r 2A = k 2AC A (5)
where A, B, and C are chemical species, r i j is the reaction rate of Table 1: Values of parameters for the veri�cation case study.
the ith reaction with respect to the jth species, and ki j is the kinetic
rate constant for the ith reaction with respect to the jth species. Variable Value Units
Pure A is fed at a rate of 100 mol/s, a temperature of 423 K, and a
E 1 /R 4000 K
concentration of 0.1 mol/L. The molar �ow rates of each species,
E 2 /R 9000 K
F A , F B , and FC , and the temperature, T , as functions of the reactor
CT (0) 0.1 mol/L
volume, V , are the quantities of interest. Mole balances on each
H Rx 1A -20,000 J/(mol of A reacted in reaction 1)
species A, B, and C give the ODEs
H Rx 2A -60,000 J/(mol of A reacted in reaction 2)
dF A 90 J/mol· K
= rA (6) C PA
dV CPB 90 J/mol· K
dF B
= rB (7) C PC 180 J/mol· K
dV Ua 4000 J/m3 · s· K
dFC Ta 373 K
= rC (8)
dV
where r i is the net reaction rate of species i. The initial conditions
are F A (0) = 100 mol/s, F B (0) = 0 mol/s, FC (0) = 0 mol/s, and
T (0) = 423 K. are at steady-state but vary spatially along the volume of the re-
The corresponding elementary rate laws that describe reactions actor, hence V is the independent variable. The explicit equations
1 and 2 from (4) and (5), respectively, are needed to complete the system of equations are given in (9)–(19)
and Table 1.
r 1A = k 1AC A (9)
2
r 2A = k 2AC A (10) REFERENCES
where C A is the concentration of species A. The relative rates are [1] J. Ancheyta-Juarez and J. A. Murillo-Hernandez. 2000. A simple method for
estimating gasoline, gas, and coke yields in FCC processes. Energy and Fuels 14
r 1B = r 1A = k 1AC A (11) (2000), 373–379.
[2] J. Carver and G. K. Thiruvathukal. 2013. Software engineering need not be
1 k 2A 2 di�cult. Workshop on Sustainable Software for Science: Practice and Experiences,
r 2C = r 2A = C (12)
2 2 A SuperComputing Conference (2013). http://dx.doi.org/10.6084/m9.�gshare.830442.
Equations (9)–(12) are combined to yield the net rates, [3] B. Ekmekci, C. E. McAnany, and C. Mura. 2016. An introduction to programming
for bioscientists: A Python-based primer. PLOS Computational Biology 12 (2016),
2 e1004867.
r A = r 1A + r 2A = k 1AC A k 2AC A (13)
[4] H. S. Fogler. 2011. Essentials of Chemical Reaction Engineering (1st. ed.). Prentice
r B = r 1B = k 1AC A (14) Hall, Boston, MA.
[5] H. S. Fogler and M. Tikmani. [n. d.]. Polymath tutorial on Ordinary Di�erential
k 2A 2 Equation Solver. ([n. d.]). Retrieved January 4, 2018 from http://umich.edu/
rC = r 2C = C (15)
2 A ~elements/5e/tutorials/ODE_Equation_Tutorial.pdf
The gas-phase stoichiometry without pressure drop is used to [6] A. N. Ford Versypt. 2017. Choose Your Own Kinetics Adventure: Student-
Designed Case Studies for Chemical Reaction Engineering Course Projects. Trans-
de�ne the concentration of species A as actions and Techniques in STEM Education In Press (2017).
[7] A. N. Ford Versypt, G. K. Harrell, and A. N. McPeak. 2017. A pharmacokinet-
F A T (0)
C A = CT (0) (16) ic/pharmacodynamic model of ACE inhibition of the renin-angiotensin system
FT T for normal and impaired renal function. Computers and Chemical Engineering
104 (2017), 311–322.
where the total �ow rate is de�ned by [8] T. Hall and J-P Stacey. 2009. Chapter 2: Designing Software. In Python 3 for
Absolute Beginners. Springer, New York.
FT = F A + F B + FC (17) [9] D. M. Hamby. 1994. Review of techniques for parameter sensitivity analysis
of environmental models. Environmental Monitoring and Assessment 32 (1994),
The rate constants depend on the temperature through the fol- 135–154.
lowing Arrhenius functions: [10] A. K. Hartmann. 2015. Big Practical Guide to Computer Simulations (2nd ed.).
✓ ◆ World Scienti�c, Hackensack, NJ.
E1 1 1
k 1A = 10 exp s 1 (18) [11] F. M. Hemez and J. R. Kamm. 2008. A brief overview of the state-of-the-practice
R T (0) T and current challenges in solution veri�cation. In Computational Methods in
✓ ◆ Transport: Veri�cation and Validation, F. Graziani (Ed.). Springer-Verlag, Berlin,
E2 1 1 L 229–250.
k 2A = 0.09 exp (19) [12] D. J. Higham and N. J. Higham. 2005. MATLAB Guide (2nd ed.). Society for
R T (0) T mol · s Industrial and Applied Mathematics, Philadelphia.
The energy balance for the reactor is [13] J. M. Kinder and P. Nelson. 2015. A Student’s Guide to Python for Physical Modeling.
Princeton University Press, Princeton, NJ.
dT U a(Ta T ) + r 1A H Rx 1A + r 2A H Rx 2A [14] J. Kiusalaas. 2005. Numerical Methods in Engineering with Python. Cambridge
= (20) University Press, New York.
dV F AC P A + F B C P B + F C C P C
[15] C. S. Lent. 2013. Learning to Program with MATLAB: Building GUI Tools. Wiley,
The values for the remaining parameters representing physical Hoboken, NJ.
[16] MathWorks. [n. d.]. App Building. ([n. d.]). Retrieved February 15, 2018 from
constants are listed in Table 1. https://www.mathworks.com/help/matlab/gui-development.html
To summarize, the system of ODEs for the veri�cation case is [17] MathWorks. [n. d.]. Create a Simple App Using GUIDE. ([n. d.]). Retrieved
given by (6)–(8) and (20) for ddVF A d F B d FC
, dV , dV , and dV
dT , describing February 15, 2018 from https://www.mathworks.com/help/matlab/creating_guis/
about-the-simple-guide-gui-example.html
the molar �ow rates of species, A, B, and C, in mol/s and tempera- [18] C. B. Moler. 2004. Numerical Computing with MATLAB. Society for Industrial
ture, T , in K in a non-isothermal plug �ow reactor. The reactions and Applied Mathematics, Philadelphia.
[19] Oliver Woodford. 2013 (accessed November 12, 2016). export_�g: A MATLAB
toolbox for exporting publication quality �gures. https://github.com/altmany/
export_�g.
[20] J. M. Osborne, M. O. Bernabeu, M. Bruna, B. Calderhead, J. Cooper, N. Dalchau,
S.-J. Dunn, A. G. Fletcher, R. Freeman, D. Groen, B. Knapp, G. J. McInerny, G. R.
Mirams, J. Pitt-Francis, B. Sengupta, D. W. Wright, C. A. Yates, D. J. Gavaghan,
S. Emmott, and C. Deane. 2014. Ten Simple Rules for E�ective Computational
Research. PLOS Computational Biology 10 (2014), e1003506.
[21] A. Prlic and J. B. Procter. 2012. Ten simple rules for the open development of
scienti�c software. PLOS Computational Biology 8 (2012), e1002802.
[22] P. J. Roache. 1998. Veri�cation of codes and calculations. AIAA Journal 36, 5
(1998), 696–702.
[23] K. Rother, W. Potrzebowski, T. Puton, M. Rother, E. Wywial, and J. M. Bujnicki.
2011. A toolbox for developing bioinformatics software. Brie�ngs in Bioinformat-
ics 13, 2 (2011), 244–257.
[24] S. M. Ruggiero, M. R. Pilvankar, and A. N. Ford Versypt. 2017. Computational
modeling of tuberculosis granuloma activation. Processes 5 (2017), 79.
[25] M. Shacham, M. B. Cutlip, and M. Elly. [n. d.]. POLYMATH Software. ([n. d.]).
Retrieved January 4, 2018 from http://www.polymath-software.com/
[26] V. Stodden and S. Miguez. 2013. Best practices for computational science: software
infrastructure and environments for reproducible and extensible research. (2013).
http://dx.doi.org/10.2139/ssrn.2322276.
[27] G. Wilson. 2016. Software Carpentry: lessons learned [version 2]. F1000Research
3 (2016), 62. https://doi.org/10.12688/f1000research.3-62.v2
[28] G. Wilson, D. A. Aruliah, C. T. Brown, N. P. C. Hong, M. Davis, R. T. Guy, S. H. D.
Haddock, K. D. Hu�, I. M. Mitchell, M. D. Plumbley, B. Waugh, E. P. White, and
P. Wilson. 2014. Best Practices for Scienti�c Computing. PLOS Biology 12 (2014),
e1001745.