A First Course on Kinetics and Reaction Engineering Example S4.5

Similar documents
over The idea is to construct an algorithm to solve the IVP ODE (9.1)

Assignment 4 (Sol.) Introduction to Data Analytics Prof. Nandan Sudarsanam & Prof. B. Ravindran

over The idea is to construct an algorithm to solve the IVP ODE (8.1)

ChE 400: Applied Chemical Engineering Calculations Tutorial 6: Numerical Solution of ODE Using Excel and Matlab

Workpackage 5 - Ordinary Differential Equations

Euler s Methods (a family of Runge- Ku9a methods)

Partial Derivatives (Online)

MATH 51: MATLAB HOMEWORK 3

Dynamics and Vibrations Mupad tutorial

Mathematical Methods and Modeling Laboratory class. Numerical Integration of Ordinary Differential Equations

Regression Solver. User Manual. Process Design and Gas Processing Laboratory Illinois Institute of Technology Chicago, IL,

ODE IVP. An Ordinary Differential Equation (ODE) is an equation that contains a function having one independent variable:

Homework Set 5 (Sections )

Ordinary differential equations solving methods

dy = dx y dx Project 1 Consider the following differential equations: I. xy II. III.

tutorial i: Using matcont for numerical integration of ODEs

Assignment: Backgrounding and Optical Flow.

Lesson 16: More on Modeling Relationships with a Line

Refraction of Light. Research Problem. Materials. Procedure. Due Date. Glass Block Protractor Ruler PENCIL 4 Pins Cardboard

AOE 5204: Homework Assignment 4 Due: Wednesday, 9/21 in class. Extended to Friday 9/23 Online Students:

MATH2070: LAB 3: Roots of Equations

Instruction Manual: Relaxation Algorithm

Study Guide for Test 2

Contents. Implementing the QR factorization The algebraic eigenvalue problem. Applied Linear Algebra in Geoscience Using MATLAB

MS&E 226: Small Data

Linear Regression. Problem: There are many observations with the same x-value but different y-values... Can t predict one y-value from x. d j.

=.1( sin(2πx/24) y) y(0) = 70.

Constrained Optimization

2.9 Linear Approximations and Differentials

A1:Orthogonal Coordinate Systems

Introduction to numerical algorithms

Nested functions & Local functions

Objectives. Materials

EGR 111 Loops. This lab is an introduction to loops, which allow MATLAB to repeat commands a certain number of times.

Euler s Method with Python

Bivariate Linear Regression James M. Murray, Ph.D. University of Wisconsin - La Crosse Updated: October 04, 2017

(Part - 1) P. Sam Johnson. April 14, Numerical Solution of. Ordinary Differential Equations. (Part - 1) Sam Johnson. NIT Karnataka.

Polymath 6. Overview

4 Visualization and. Approximation

HMC CS 158, Fall 2017 Problem Set 3 Programming: Regularized Polynomial Regression

Approximating Square Roots

Introduction to Computational Mathematics

The Euler and trapezoidal stencils to solve d d x y x = f x, y x

hp calculators HP 9g Statistics Non-Linear Regression Non-Linear Regression Practice Solving Non-Linear Regression Problems

1 Variations of the Traveling Salesman Problem

6.867 Machine learning, lecture 1 (Jaakkola) 1

An Investigation into Iterative Methods for Solving Elliptic PDE s Andrew M Brown Computer Science/Maths Session (2000/2001)

[1] CURVE FITTING WITH EXCEL

The Differential df, the Gradient f, & the Directional Derivative Dû f sec 14.4 (cont), Goals. Warm-up: Differentiability. Notes. Notes.

Homework Set #2-3, Math 475B

CHAPTER 1. Introduction

27. Tangent Planes & Approximations

To graph the point (r, θ), simply go out r units along the initial ray, then rotate through the angle θ. The point (1, 5π 6. ) is graphed below:

CS143: Introduction to Computer Vision Homework Assignment 3

Week 3: Perceptron and Multi-layer Perceptron

1. Practice the use of the C ++ repetition constructs of for, while, and do-while. 2. Use computer-generated random numbers.

MATH2070: LAB 3: Roots of Equations

and F is an antiderivative of f

Figure 4.1: The evolution of a rooted tree.

Lagrange Multipliers and Problem Formulation

1. The following graph is not Eulerian. Make it into an Eulerian graph by adding as few edges as possible.

AM205: lecture 2. 1 These have been shifted to MD 323 for the rest of the semester.

Using Excel for Graphical Analysis of Data

(c) 0 (d) (a) 27 (b) (e) x 2 3x2

Machine Learning and Computational Statistics, Spring 2015 Homework 1: Ridge Regression and SGD

2. Use the above table to transform the integral into a new integral problem using the integration by parts formula below:

CS420 Project IV. Experimentation with Artificial Neural Network Architectures. Alexander Saites

Exercises for a Numerical Methods Course

Measurement of display transfer characteristic (gamma, )

The Game of Criss-Cross

1. Suppose that the equation F (x, y, z) = 0 implicitly defines each of the three variables x, y, and z as functions of the other two:

CS1114: Study Guide 2

Learning from Data Linear Parameter Models

Selecting the Right Model Studio - Excel 2007 Version

Expectation-Maximization Methods in Population Analysis. Robert J. Bauer, Ph.D. ICON plc.

Controlling Macro Flow

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras

MA 1128: Lecture 02 1/22/2018

Lab 2: Introducing XPPAUT

Exploring Fractals through Geometry and Algebra. Kelly Deckelman Ben Eggleston Laura Mckenzie Patricia Parker-Davis Deanna Voss

Assignment 2. with (a) (10 pts) naive Gauss elimination, (b) (10 pts) Gauss with partial pivoting

1 Introduction: Using a Python script to compile and plot data from Fortran modular program for Newton s method

10.4 Linear interpolation method Newton s method

Advanced Digital Signal Processing Adaptive Linear Prediction Filter (Using The RLS Algorithm)

14.2 The Regression Equation

Introduction to Matlab. SAMSI Undergraduate Workshop May 15, 2006

COPYRIGHTED MATERIAL INTRODUCTION TO ASPEN PLUS CHAPTER ONE

ENCM 339 Fall 2017 Lecture Section 01 Lab 9 for the Week of November 20

AMS527: Numerical Analysis II

3.9 LINEAR APPROXIMATION AND THE DERIVATIVE

Multivariate Calculus: Review Problems for Examination Two

1 2 (3 + x 3) x 2 = 1 3 (3 + x 1 2x 3 ) 1. 3 ( 1 x 2) (3 + x(0) 3 ) = 1 2 (3 + 0) = 3. 2 (3 + x(0) 1 2x (0) ( ) = 1 ( 1 x(0) 2 ) = 1 3 ) = 1 3

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s.

1.OA.1. 1.OA.2 MP: Make sense of problems and persevere in solving them MP: Model with mathematics. Common Core Institute

A straight line is the graph of a linear equation. These equations come in several forms, for example: change in x = y 1 y 0

Learning Meanings for Sentences with Recursive Autoencoders

1. What specialist uses information obtained from bones to help police solve crimes?

APPM 2460: Week Three For, While and If s

In SigmaPlot, a restricted but useful version of the global fit problem can be solved using the Global Fit Wizard.

Epidemic spreading on networks

Transcription:

Example S4.5 Problem Purpose The purpose of this example is to illustrate how to use the MATLAB template file FitNumDifMR.m to perform a regression analysis for multiple response data with a model that consists of a set of initial value ordinary differential equations that must be solved numerically. Problem Statement Suppose that 8 experiments were performed wherein the values of two variables, x1 and x2 were set and then the values of variables y1, y2 and y3 were measured. The results of the experiments are shown in Table 1. Additionally suppose that equations (1) through (3) constitute a model of the experiments. The goal here is to fit the model to the data and assess the quality of the fit. Table 1. Data for Example 1. x1 x2 ŷ1 ŷ2 ŷ3 0.4809 36.0 0.4188 0.0063 0.0298 0.4809 143.0 0.2882 0.0046 0.1200 0.4809 296.0 0.2188 0.0027 0.1682 0.4809 561.0 0.0868 0.0011 0.2578 0.4725 25.0 0.4163 0.0067 0.0279 0.4725 185.0 0.2629 0.0043 0.1334 0.4725 335.5 0.1598 0.0021 0.2056 0.4725 462.0 0.1074 0.0014 0.2326 dy 1 dv = θ y ; y ( 0) = x 1 1 1 1 (1) dy 2 dv = θ y θ 1 1 ( +θ 2 3)y 2 ; y 2 ( 0) = 0 (2) dy 3 dv = θ y ; y ( 0) = 0 2 2 3 (3) Problem Analysis The data points in this problem have three response variables, and the value of all three responses was measured for every data point. In other words, the data set in this problem is a complete, multiple AFCoKaRE, Example S4.5 1

response data set. The model consists of a set of initial value ordinary differential equations. These facts indicate that the model can be fit to the data using the MATLAB template file FitNumDifMR.m. Note: The solution presented here will read very much like the solution to Example S4.4. The reasons are threefold. First, this is the exact same problem. In Example S4.4 the model equations used are the analytical solution of equations (1) through (3) here; that s the only difference. Second, the use of the template file FitNumDifMR.m is very, very similar to the use of FitNumAlgMR.m and FitNumDifSR.m. Third, I m lazy; it just didn t seem worth the effort to rewrite the solution so it says essentially the same thing as Example S4.4, but using different words. Problem Solution Notice, the model equations do not contain unknowns represented by u. That is because in this problem, the responses are equal to the unknowns in the model equations. You may recall that the template file is set up to solve the model equations for u and then use the result to calculate y. Here it is trivial to recast the equations in that form, as shown in equations (4) through (9). As was done in Example S4.4, the base-10 logarithms of the parameters will be used as the guesses to shrink the range of possible values. du 1 dv = θ u ; u ( 0) = x 1 1 1 1 (4) du 2 dv = θ u θ 1 1 ( +θ 2 3)u 2 ; u 2 ( 0) = 0 (5) du 3 dv = θ u ; u ( 0) = 0 2 2 3 (6) y 1 = u 1 ( x 2 ) (7) y 2 = u 2 ( x 2 ) (8) y 3 = u 3 ( x 2 ) (9) The responses won t always be equal to the unknowns (see Example S4.2). Therefore, from this point forward, equations (4) through (6) will be taken to be the model equations and equations (7) through (9) will be taken to represent the functions f referred to in the informational reading. Following the step-by-step instructions for the use of FitNumDifMR.m, a copy of that file was saved as S4_Example_5.m and is provided with this supplemental unit. The introductory comment and the function name were then changed as in all the other examples in this supplemental unit. There are six required modifications that must be made each time FitNumDifMR.m is used. They are indicated in the code by a comment that begins % EDIT HERE. The first three are exactly the same as in Example S4.4 and won t be shown here. AFCoKaRE, Example S4.5 2

The fourth required modification appears within the internal function, odeqns. It involves evaluating the three derivatives that constitute the model, namely equations (4) through (6), and returning the results as a column vector, dudv. You can see that the only argument received by odeqns is the values of u1, u2 and u3, in the form of a column vector named u. Looking at the model equations (4) through (6), you can see that they also contain the model parameters, θ1, θ2 and θ3. The parameters are available in the column vector p. Recalling that the guesses I ll provide for the parameters are the base 10 logs of the actual parameters, θ1 is equal to 10^p(1), θ2 is 10^p(2), and θ3 is 10^p(3). With this knowledge, the modification of internal function odeqns is straightforward, as shown In Listing 1.! % Function that evaluates the ODEs function dudv = odeqns(v,u) % Current parameter values are available in column vector p % Current set variable values are available in column vector x_set dudv = [ -10^p(1)*u(1); 10^p(1)*u(1) - (10^p(2)+10^p(3))*u(2); 10^p(2)*u(2); end % of internal function odeqns Listing 1. Internal function odeqns after modification. The other two required modifications takes place within the internal function, mrmodel. They occur within a loop through each of the experimental data points, i. The first is where initial values for the model unknowns, u1, u2 and u3, for data point i need to be entered along with the initial and final values of the independent variable, v. It can be seen in equations (4) through (6) that the initial value of v is zero and the initial values of u1, u2 and u3 are x1, 0 and 0, respectively. Equations (7) through (9) show that the final value of v is equal to x2. The values of the set variables for data point i are available at this point in the column vector named x_set; hence x2 is available as x_set(2). The corresponding modification of the template file is shown in Listing 2. Just a few lines after that modification, still within the loop through the data points within the internal function, mrmodel, the final required modification must be made. This modification is located just after the model equations have been solved for the values of u at the specified final v, and the comment indicates that the values of the response variables need to be calculated. In this problem, the response variables are calculated using equations (7) through (9), so this modification simply involves adding the code to calculate y1, y2 and y3 using those equations, as also shown in Listing 2. AFCoKaRE, Example S4.5 3

function y = mrmodel(p_current) % Declare y y = zeros(n_data,n_resp); % Make the current parameters available to the model equations p = p_current; for i = 1:n_data % Make the set variables available to the model equations for j = 1:n_set x_set(j) = x(i,j); end % Initial and final values v0 = 0.0; u0 = [ x_set(1); 0.0; 0.0; vf = x_set(2); % Solve the set of ordinary differential model equations [v,uu] = ode45(@odeqns,[v0 vf],u0); last_value = length(v); u = uu(last_value,:); % Use the solution to calculate the responses, y(1), y(2),... % by evaluating f1(u(1),...,u(n),x_set(1),...,x_set(n_set)), % f2(u(1),...,u(n),x_set(1),...,x_set(n_set)), etc. y(i,:) = [ u(1); u(2); u(3); end end % of internal function mrmodel Listing 2. Internal function mrmodel after modification. That completes the required modification of S4_Example_5.m, and it can be saved in the current MATLAB working directory or in a directory that is part of the MATLAB search path. When S4_Example_5 is executed, it must be passed a column vector that contains guesses for each of the base-ten logs of the three parameters in the model, as discussed previously. From this point on, the process is exactly the same as in Example S4.4. Guesses were provided, S4_Example_5 was executed and the process of copying the results (pf) into p_guess and re-executing S4_Example_5.m was repeated until the returned parameter values were the same as the values guessed, indicating that the minimization had converged. Listing 3 shows the final parameter copy and the text output from running S4_Example_5.m. In addition to the text output, nine figures were generated, including Figures 1 through 4 included here. By AFCoKaRE, Example S4.5 4

comparison, you can see that the results are essentially the same as those presented in Example S4.4, which is expected since the models are equivalent and the data are identical. >> p_guess = [ -2.4943-0.8521-1.1163 >> S4_Example_5(p_guess) Best Values for the Parameters: pf = -2.4943-0.8521-1.1163 Listing 3. Output from the final re-execution of S5_Example_1.m. Figure 1. Parity plot showing the predicted versus measured values of response variable y1. AFCoKaRE, Example S4.5 5

Figure 2. Parity plot showing the predicted versus measured values of response variable y2. Figure 3. Parity plot showing the predicted versus measured values of response variable y3. AFCoKaRE, Example S4.5 6

Figure 4. Residuals plot for response variable y3 versus set variable x2. AFCoKaRE, Example S4.5 7