MediaWiki API result

This is the HTML representation of the JSON format. HTML is good for debugging, but is unsuitable for application use.

Specify the format parameter to change the output format. To see the non-HTML representation of the JSON format, set format=json.

See the complete documentation, or the API help for more information.

{
    "batchcomplete": "",
    "continue": {
        "gapcontinue": "System_stability_and_digital_control_-_2014",
        "continue": "gapcontinue||"
    },
    "warnings": {
        "main": {
            "*": "Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/> for notice of API deprecations and breaking changes."
        },
        "revisions": {
            "*": "Because \"rvslots\" was not specified, a legacy format has been used for the output. This format is deprecated, and in the future the new format will always be used."
        }
    },
    "query": {
        "pages": {
            "33": {
                "pageid": 33,
                "ns": 0,
                "title": "Software for integrating ODEs",
                "revisions": [
                    {
                        "contentformat": "text/x-wiki",
                        "contentmodel": "wikitext",
                        "*": "== Background ==\n\nNumerically integrating ODE's is something you should have mastered in your pre-requisite 3E4 course. If you are not familiar with this topic, it is your responsibility to quickly catch up, because we will use this intensively for the rest of the course.\n\nHere is a tutorial a wrote a few years ago when I [https://learnche.org/3E4/Software_tutorial/Integration_of_ODEs taught 3E4 in 2010]. The tutorial below is similar, but uses a reactor design example.\n\n\n== Example ==\nThe example we will work with is a common modelling reaction: a liquid-based stirred tank reactor, with (initially) constant physical properties, a second order chemical reaction where species A is converted to B according to  \\({\\sf A} \\rightarrow {\\sf B} \\), with reaction rate \\(r = k C_{\\sf A}^2\\).  One can find the time-dependent mass balance for this system to be:\n\n\\[ \\frac{dC_{\\sf A}(t)}{dt} = \\frac{F(t)}{V} \\bigg( C_{{\\sf A},\\text{in}} - C_{\\sf A} \\bigg) - k C_{\\sf A}^2 \\]\n\nwhere \\(C_{{\\sf A},\\text{in}} = 5.5\\) mol/L, we will initially assume constant volume of \\(V = 100\\) L and constant inlet flow of \\(F(t) = 20.1 \\) L/min.  The reaction rate constant is 0.15 \\(\\frac{\\text{L}}{\\text{mol}.\\text{min}}\\).  We must specify an initial condition for every differential equation: we will let \\( C_{\\sf A}(t=0) = 0.5\\) mol/L. \n\nIn the code below we will integrate the ODE from \\(t_\\text{start} = 0.0\\) minutes up to \\(t_\\text{final} = 10.0\\) minutes and plot the time-varying trajectory of concentration in the tank.\n\n== MATLAB code ==\n\nIn a file called '''<tt>tank.m</tt>''':\n<syntaxhighlight lang=\"matlab\">\nfunction d_depnt__d_indep = tank(indep, depnt)\n\n% Dynamic balance for a CSTR\n%\n% C_A = y(1) = the concentration of A in the tank, mol/L\n%\n% Returns dy/dt = F/V*(C_{A,in} - C_A) - k*C_A^2\n\n%    indep: the independent ODE variable, such as time or length or the reactor\n%    depnt: a VECTOR of dependent variables\n% \n%    Returns:\n%\n%    d(depnt)\n%   ---------- = a vector of ODEs\n%    d(indep)\n \n% Assign some variables for convenience of notation: one row per DEPENDENT variable\nCA = depnt(1);\n\n% Constant and other equations\nF = 20.1;      % L/min\nCA_in = 2.5;   % mol/L\nV = 100;       % L\nk = 0.150;     % L/(min.mol)\n\n% The output from the ODE function must be a COLUMN vector, with n rows\n% n = how many ODE's in this system?\nn = numel(depnt); d_depnt__d_indep = zeros(n,1);\n\n% Specify every element in the vector below: 1, 2, ... n\nd_depnt__d_indep(1) = F/V*(CA_in - CA) - k*CA^2;\n</syntaxhighlight>\n\nIn a separate file (any name), for example: '''<tt>ode_driver.m</tt>''', which will \"drive\" the ODE solver:\n<syntaxhighlight lang=\"matlab\">\n% Integrate the ODE\n% -----------------\n\n% Set the time range:\nt_start = 0;\nt_final = 10.0;\n\n% Set the initial condition(s):\nCA_t_zero = 0.5;\n\n% Integrate the ODE(s):\n[t, y] = ode45(@tank, [t_start, t_final], [CA_t_zero]);\n\n% Plot the results:\nclf;\nplot(t, y)\ngrid('on')\nxlabel('Time [minutes]')\nylabel('Concentration of A [mol/L]')\n</syntaxhighlight>\n\nA plot from this code shows the system stabilizing after about 9 minutes.\n[[Image:Single-ode-MATLAB.png | 550px]]\n\n\nLet's take a look at the MATLAB output:\n<syntaxhighlight lang=\"matlab\">\n>> t(1:10)\nans =\n         0\n    0.0689\n    0.1378\n    0.2067\n    0.2757\n    0.5257\n    0.7757\n    1.0257\n    1.2757\n    1.5257\n\n>> y(1:10)\nans =\n    0.5000\n    0.5248\n    0.5490\n    0.5726\n    0.5956\n    0.6742\n    0.7452\n    0.8090\n    0.8662\n    0.9171\n</syntaxhighlight>\nMATLAB places the points at unequal step sizes of time.  This is what their documentation has to say:\n\n:The MATLAB ODE solvers utilize these methods by taking a step, estimating the error at this step, checking to see if the value is greater than or less than the tolerance, and altering the step size accordingly. These integration methods do not lend themselves to a fixed step size. Using an algorithm that uses a fixed step size is dangerous since you can miss points where your signal frequency is greater than the solver frequency. Using a variable step ensures that a large step size is used for low frequencies and a small step size is used for high frequencies. The ODE solvers within MATLAB are optimized for a variable step, run faster with a variable step size, and clearly the results are more accurate.\n\n== Example with coupled ODEs ==\n\nWe will now expand our example to a system of two coupled ODEs. Still in the same reactor we are now considering the rate constant to be a function of temperature: \\(k = 0.15 e^{- E_a/(RT)}\\) L/(mol.min), with \\(E_a = 5000\\) J/(mol) and R = \\(8.314 \\) J/mol.K, and \\(T(t)\\) is the time-varying tank temperature, measured in Kelvin.  Furthermore, the reaction is known to release heat, with \\(\\Delta H_r = -590\\) J/mol.  The time-dependent mass and energy balance for this system is now:\n\n\\[ \\begin{align*}\\frac{dC_{\\sf A}(t)}{dt} &= \\frac{F(t)}{V} \\bigg( C_{{\\sf A},\\text{in}} - C_{\\sf A} \\bigg) - 0.15 e^{- E_a/(RT)} C_{\\sf A}^2 \\\\ \\frac{dT(t)}{dt} &= \\frac{F(t)\\rho C_p(T)}{V \\rho C_p(T)}\\bigg(T_\\text{in} - T(t) \\bigg) - \\frac{0.15 e^{- E_a/(RT)} C_{\\sf A}^2 V (\\Delta H_r)}{V \\rho C_p}\\end{align*}\\]\n\nwhere \\(C_{{\\sf A},\\text{in}} = 2.5\\) mol/L, \\(T_\\text{in} = 288\\) K; we will initially assume constant volume of \\(V = 100\\) L and constant inlet flow of \\(F(t) = 20.1 \\) L/min.   Also, \\(C_p(T) = 4.184 - 0.002(T-273) \\) J/(kg.K), the molar heat capacity of the liquid phase system, a weak function of the system temperature. The density of the liquid phase is \\(\\rho=1.05\\) kg/L. We need two initial conditions as well: \n* \\( C_{\\sf A}(t=0) = 0.5\\) mol/L\n* \\(T(t=0) = 295 K \\)\n\nIn the code below we will integrate the ODE from \\(t_\\text{start} = 0.0\\) minutes up to \\(t_\\text{final} = 45.0\\) minutes and plot the time-varying trajectory of concentration in the tank.\n\nThe following code appears in an m-file called: '''<tt>tank_coupled.m</tt>'''\n<syntaxhighlight lang=\"matlab\">\nfunction d_depnt__d_indep = tank_coupled(indep, depnt)\n\n% Dynamic balance for a CSTR\n%    C_A = y(1) = the concentration of A in the tank, [mol/L]\n%    T   = y(2) = the tank temperature, [K]\n%\n%    Returns dy/dt = [F/V*(C_{A,in} - C_A) - k*C_A^2       ]\n%                    [F/V*(T_in - T) - k*C_A^2*HR/(rho*Cp) ]\n%\n\n%    indep: the independent ODE variable, such as time or length or the reactor\n%    depnt: a VECTOR of dependent variables\n% \n%    Returns:\n%\n%    d(depnt)\n%   ---------- = a vector of ODEs\n%    d(indep)\n \n% Assign some variables for convenience of notation: one row per DEPENDENT variable\nCA = depnt(1);\nT = depnt(2);\n\n% Constants\nF = 20.1;     % L/min\nCA_in = 2.5;  % mol/L\nV = 100.0;    % L\nk0 = 0.15;    % L/(mol.min)\nEa = 5000;    % J/mol\nR = 8.314;    % J/(mol.K)\nHr = -590;    % J/mol\nT_in = 288;   % K\nrho = 1.050;  % kg/L\n% Algebraic equations\nk = k0 * exp(-Ea/(R*T));  % L/(mol.min)\nCp = 4.184 - 0.002*(T-273);  % J/(kg.K)\n\n% Output from this ODE function must be a COLUMN vector, with n rows\n% n = how many ODEs in this system?\n\nn = numel(depnt); d_depnt__d_indep = zeros(n,1);\n\nd_depnt__d_indep(1) = F/V*(CA_in - CA) - k*CA^2;\nd_depnt__d_indep(2) = F/V*(T_in - T) - (Hr*k*CA^2)/(rho*Cp);\n</syntaxhighlight>\nIn a separate file (any name), for example: '''<tt>ode_driver.m</tt>''', which will \"drive\" the ODE solver:\n<syntaxhighlight lang=\"matlab\">\n% Integrate the ODE\n% -----------------\n\n% Set the time range:\nt_start = 0;\nt_final = 45.0;\n\n% Set the initial condition(s):\nCA_t_zero = 0.5;\nT_t_zero = 295;\n\n% Integrate the ODE(s):\n[t, y] = ode45(@tank_coupled, [t_start, t_final], ...\n                              [CA_t_zero, T_t_zero]);\n\n% Plot the results:\nclf;\nsubplot(2, 1, 1)\nplot(t, y(:,1))\nxlabel('Time [minutes]')\nylabel('Concentration of A [mol/L]')\ngrid('on')\n\nsubplot(2, 1, 2)\nplot(t, y(:,2), 'r')\nxlabel('Time [minutes]')\nylabel('Temperature in tank [K]')\ngrid('on')\n\nprint('-dpng', 'coupled-ode-MATLAB.png')\n</syntaxhighlight>\nThe trajectories produced by the above code are shown below.  Do they make engineering sense?\n[[Image:Coupled-ode-MATLAB.png | 550px]]\n\n\n;'''Important notes'''\n\n:* Each trajectory (ODE) must have an initial condition.\n:* The function that specifies the ODE must return a ''column'' vector with \\(n\\) entries, one for each ODE.\n:* Algebraic equations may be included in the ODE function.  For example:\n:** \\(C_p = 4.184 - 0.002(T-273)\\) is an algebraic function\n:** If the inlet flow varied over time according to \\(F(t) = 20.1 + 2\\sin(t)\\) then this algebraic equation could be added.\n:* Numerical integration allows for discontinuities. For example, a step input at \\(t=50\\) minutes in the inlet flow can be coded as\n::\n<syntaxhighlight lang=\"matlab\">\nif t < 50\n    F = 20.1\nelse\n    F = 25.1\nend\n</syntaxhighlight>"
                    }
                ]
            },
            "24": {
                "pageid": 24,
                "ns": 0,
                "title": "Suggested readings",
                "revisions": [
                    {
                        "contentformat": "text/x-wiki",
                        "contentmodel": "wikitext",
                        "*": "The following printed materials are recommended as supplementary readings.  In alphabetical order:\n{| class=\"wikitable sortable\"\n|-\n! Author(s)\n! Title\n! Library link\n! Google search\n! Amazon.CA link\n|-\n| Ogunnaike and Ray\n| Process dynamics, modeling, and control\n| [http://catalogue.mcmaster.ca/catalogue/Record/995626 McMaster]\n| [https://www.google.ca/search?q=ISBN%3A9780195091199 Google]\n| [http://www.amazon.ca/s/ref=nb_sb_noss?url=field-keywords=9780195091199 Amazon]\n|-\n| Seborg, Edgar, Mellichamp and Doyle *\n| Process Dynamics and Control\n| [http://catalogue.mcmaster.ca/catalogue/Record/463170 McMaster]\n| [https://www.google.ca/search?q=ISBN%3A9780470128671 Google]\n| [http://www.amazon.ca/s/ref=nb_sb_noss?url=field-keywords=9780470128671 Amazon]\n|-\n| Smith, C. and Corripio, A.\n| Principles And Practice Of Automatic Process Control\n| [http://catalogue.mcmaster.ca/catalogue/Record/1270221 McMaster]\n| [https://www.google.ca/search?q=ISBN%3A9780471431909 Google]\n| [http://www.amazon.ca/s/ref=nb_sb_noss?url=field-keywords=9780471431909 Amazon]\n|-\n| Stephanopoulos, G\n| Chemical Process Control  An Introduction To Theory And Practice\n| [http://catalogue.mcmaster.ca/catalogue/Record/90380 McMaster] \n| [https://www.google.ca/search?q=ISBN%3A9780131286290 Google]\n| [http://www.amazon.ca/s/ref=nb_sb_noss?url=field-keywords=9780131286290 Amazon]\n|-\n|}\n\n<nowiki>*</nowiki> The book by Seborg ''et al.'' is easily available new or second hand, as it was the prescribed textbook in 2013 (Marlin's book was prescribed in 2012). I will make reference to the chapters from Seborg on the website as well."
                    }
                ]
            }
        }
    }
}