CHEE 222: PROCESS DYNAMICS AND NUMERICAL METHODS

Similar documents
How to create Virtual Channels Tutorial

AP CALCULUS SUMMER WORKSHEET

AP CALCULUS SUMMER WORKSHEET

Using this definition, it is possible to define an angle of any (positive or negative) measurement by recognizing how its terminal side is obtained.

Chapter 1. Functions 1.3. Trigonometric Functions

Math 12 Final Exam Review 1

Core 3 (A2) Practice Examination Questions

Learning Objectives for Math 165

Chapter 2: Differentiation

CK- 12 Algebra II with Trigonometry Concepts 1

Dear Future CALCULUS Student,

Chapter 2: Differentiation

SUMO. Introduction (Version 1.0)

Math 551 Homework Assignment 3 Page 1 of 6

Unit #3 : Differentiability, Computing Derivatives

2. Find the midpoint of the segment that joins the points (5, 1) and (3, 5). 6. Find an equation of the line with slope 7 that passes through (4, 1).

NAME: DATE: CLASS: AP CALCULUS AB SUMMER MATH 2018

Unit #3 : Differentiability, Computing Derivatives, Trig Review

Dear Future CALCULUS Student,

June 9 Math 1113 sec 002 Summer 2014

One of the powerful themes in trigonometry is that the entire subject emanates from a very simple idea: locating a point on the unit circle.

Unit 6 Trigonometric Identities

1.2 Supplement: Mathematical Models: A Catalog of Essential Functions

Matlab for Review. NDSU Matlab Review pg 1

Chapter P: Preliminaries

Topic Outline for Integrated Algebra 2 and Trigonometry-R One Year Program with Regents in June

Indiana Academic Standards for Precalculus

Calculus I Announcements

TO EARN ANY CREDIT, YOU MUST SHOW STEPS LEADING TO THE ANSWER

Math 121: Calculus 1 - Fall 2012/2013 Review of Precalculus Concepts

10.7 Trigonometric Equations and Inequalities

(e) 2 (f) 2. (c) + (d). Limits at Infinity. 2.5) 9-14,25-34,41-43,46-47,56-57, (c) (d) 2

Calculating the Derivative Using Derivative Rules Implicit Functions Higher-Order Derivatives

HIGH SCHOOL MATH CURRICULUM GRADE ELEVEN ALGEBRA 2 & TRIGONOMETRY N

Algebra 2 and Trigonometry

Function and Relation Library

10.7 Trigonometric Equations and Inequalities

Calculus: Early Transcendental Functions Lecture Notes for Calculus 101. Feras Awad Mahmoud

f(g(x)) g (x) dx = f(u) du.

Chapter P: Preliminaries

Investigating Limits in MATLAB

Unit 6 Trigonometric Identities Prove trigonometric identities Solve trigonometric equations

MAT137 Calculus! Lecture 9

Trigonometry.notebook. March 16, Trigonometry. hypotenuse opposite. Recall: adjacent

10.7 Trigonometric Equations and Inequalities

Pre-Calculus 40 Final Outline/Review:

D. 6. Correct to the nearest tenth, the perimeter of the shaded portion of the rectangle is:

USE OF MATLAB TO UNDERSTAND BASIC MATHEMATICS

MECH : a Primer for Matlab s ode suite of functions

Lecture 25: The Sine and Cosine Functions. tan(x) 1+y

f(x) f(a) Limit definition of the at a point in slope notation.

MA 8019: Numerical Analysis I Solution of Nonlinear Equations

University of Delaware Department of Mathematical Sciences Math 353 Engineering Mathematics III 06S C. Bacuta

5. Hand in the entire exam booklet and your computer score sheet.

Math Practice Exam 3 - solutions

Core Mathematics C3. You must have: Mathematical Formulae and Statistical Tables (Pink)

Formulas to remember

Intermediate Algebra Chapter 12 Review

Name Date Period. Calculater Permitted MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Core Mathematics 3 Differentiation

MATHia Unit MATHia Workspace Overview TEKS

Antiderivatives. DEFINITION: A function F is called an antiderivative of f on an (open) interval I if F (x) = f(x) for all x in I EXAMPLES:

a x a y = a x+y a x a = y ax y (a x ) r = a rx and log a (xy) = log a (x) + log a (y) log a ( x y ) = log a(x) log a (y) log a (x r ) = r log a (x).

Pre AP Algebra. Mathematics Standards of Learning Curriculum Framework 2009: Pre AP Algebra

Differentiability, Computing Derivatives, Trig Review

correlated to the Indiana Academic Standards for Precalculus CC2

Grade 11 or 12 Pre-Calculus

As we know, the three basic trigonometric functions are as follows: Figure 1

Blue Pelican Calculus First Semester

Trigonometric Identities and Equations

Math 409/509 (Spring 2011)

Next, we ll use all of the tools we ve covered in our study of trigonometry to solve some equations.

Honors Precalculus Semester 1 Review

Level 1 Advanced Mathematics Final Exam June 19, 2007

Grade Math (HL) Curriculum

Differentiability, Computing Derivatives, Trig Review. Goals:

2. Theory of the Derivative

1.3 Basic Trigonometric Functions

5 Trigonometric Functions

Math 106 Calculus 1 Topics for first exam

MATH 1040 Objectives List

Calculus & Analytic Geometry I

Math 131 Week-in-Review #11 (Final Exam Review: All previous sections as well as sections 5.5, 6.1, 6.5, and 6.7)

TRIGONOMETRIC FUNCTIONS. Copyright Cengage Learning. All rights reserved.

Numerical Methods I Solving Nonlinear Equations

MATH 1241 FINAL EXAM FALL 2012 Part I, No Calculators Allowed

Pre-Calculus II: Trigonometry Exam 1 Preparation Solutions. Math&142 November 8, 2016

Welcome to AP Calculus!!!

SESSION 6 Trig. Equations and Identities. Math 30-1 R 3. (Revisit, Review and Revive)

MAT137 - Term 2, Week 5

Optimization and Calculus

For a semi-circle with radius r, its circumfrence is πr, so the radian measure of a semi-circle (a straight line) is

SECTION A. f(x) = ln(x). Sketch the graph of y = f(x), indicating the coordinates of any points where the graph crosses the axes.

Calculus I. George Voutsadakis 1. LSSU Math 151. Lake Superior State University. 1 Mathematics and Computer Science

ADDITIONAL MATHEMATICS

Prerequisites for Math 212: Differential Equations

DRAFT - Math 101 Lecture Note - Dr. Said Algarni

An Overly Simplified and Brief Review of Differential Equation Solution Methods. 1. Some Common Exact Solution Methods for Differential Equations

Math 5 Trigonometry Chapter 4 Test Fall 08 Name Show work for credit. Write all responses on separate paper. Do not use a calculator.

Numerical Analysis Fall. Roots: Open Methods

Transcription:

CHEE 222: PROCESS DYNAMICS AND NUMERICAL METHODS Winter 2017 Implementation of Numerical Methods via MATLAB Instructor: Xiang Li

1 Outline 1. Introduction - Command, script and function - MATLAB function for mathematical functions 2. Programming Flow Control - IF-ELSE statement: Conditional commands - FOR statement: Repetitive commands - WHILE statement: Repetitive commands - Logical expressions: Description of conditions 3. Example Implementations - Direct substitution - Newton s method - Explicit Euler method

1. Introduction 2 Why MATLAB? MATLAB has become a standard tool for almost all scientific and engineering disciplines. MATLAB has become more and more popular in the R&D in industry. For CHEE 222: You don t have to perform tedious calculation by hand, and you can solve complicated problems with the principles learned in the course. Will be used again in: CHEE 311, CHEE 319, CHEE 321, CHEE 434, CHEE 412, CHEE 418

1. Introduction 3 References Moler, C. Numerical Computing with MATLAB, The MathWorks, Inc., Natick, MA (2004). (Electronic version: http://www.mathworks.com/moler) MATLAB help files Hudon, N, DeHaan, D., and Guay, M. Introduction to MATLAB. Department of Chemical Engineering, Queen s University (2006). - This MATLAB guide is available on D2L as HDG2006.pdf - Part of this presentation is prepared based on this guide.

1. Introduction Prompt line command Straightforward way to implement an operation 4 Prompt line Where your type your command Current folder Place the MATLAB file you want to call in the current folder. Workspace Existing variable are stored here.

1. Introduction 5 One to several commands in a single prompt line

1. Introduction 6 Script file A batch of commands

1. Introduction Function file A batch of commands with inputs and outputs 7 Function name should be the file name!

1. Introduction 8 Function file A batch of commands with inputs and outputs

1. Introduction 9 Function file A batch of commands with inputs and outputs

1. Introduction 10 Row Vector, Colum Vector, Matrix Math MATLAB a = ( 1 3 6 ) Approach 1 Approach 2 a = [ 1 3 6 ]; a(1) = 1; a(2) = 3; a(3) = 6; b = 2 5 8 Approach 1 Approach 2 b = [ 1; 3; 6 ]; b(1) = 2; b(2) = 5; b(3) = 8; b = b ; A = 1 2 3 4 5 6 Approach 1 Approach 2 A = [ 1 2 3; 4 5 6 ]; A(1,:) = [ 1 2 3 ]; A(2,:) = [ 4 5 6 ];

1. Introduction 11 MATLAB function as f(x) in algebraic equations (1) absin(x 1 ) + cos(x 2 ) = 0, a ln(x 1 ) + e b2 (x 1 +x ) 2 = 0, a = 1, b = 0. f(x) = 0 where x = x 1 x 2, f(x) = absin(x 1 ) + cos(x 2 ) a ln(x 1 ) + e b2 (x 1 +x 2 ), a = 1, b = 0.

1. Introduction MATLAB function as f(x) in algebraic equations (2) 12 f(x) = absin(x 1 ) + cos(x 2 ) a ln(x 1 ) + e b2 (x 1 +x 2 ) where a = 1, b = 0.5. To solve f(x) = 0 with x 0 = (1.2, 1.4), type in MATLAB prompt (command) line: or

1. Introduction MATLAB function as f(x) in algebraic equations (3) 13 f(x) = absin(x 1 ) + cos(x 2 ) a ln(x 1 ) + e b2 (x 1 +x 2 ) where a = 1, b = 0.5. To solve f(x) = 0 with x 0 = (1.2, 1.4), type in MATLAB prompt (command) line:

1. Introduction MATLAB function for f(t,x) in ODEs x = f(t, x) = absin(x 1 ) + cos(x 2 ) a ln(x 1 ) + e b2 (x 1 +x 2 ) where a = 1, b = 0.5. if MATLAB built-in ode solvers (e.g., ode45) are to be used for solution, the ODE needs to be represented in this form no matter whether time t is present in the right-hand-sides of the equations. 14 To solve x=f(t, x) for time period [0, 0.5] with x(0) = (3, 4), type in prompt line: or

1. Introduction Some MATLAB built-in functions for math functions Function Description sin(x) sine of x; x in radians cos(x) cosine of x; x in radians tan(x) tangent of x; x in radians sec(x) secant of x; x in radian csc(x) cosecant of x; x in radian cot(x) cotangent of x; x in radian asin(x) arc sine of x sinh(x) hyperbolic sine of x asinh(x) inverse hyperbolic sine of x exp(x) exponential of x log(x) natural logarithm of x log10(x) base 10 logarithm of x sqrt(x) square root of x power(x,a) x to the power of a (equivalent to x^a) abs(x) absolute value of x round(x) round x towards nearest integer floor(x) round x towards minus infinity ceil(x) round x towards infinity fix(x) round x towards zero 15

2. Programming Flow Control for Conditional and Repetitive Commands 16 IF-ElSE statements Conditional commands CONDITION is expressed via logical operations. ACTION may involve one or several commands. The math function x can be computed via the following MATLAB function myabs that involves conditional commands:

2. Programming Flow Control for Conditional and Repetitive Commands 17 FOR statements Repetitive commands (1) After the execution of the FOR loop, the value of y becomes 5. After the execution of the FOR loop, the value of vector y becomes [1, 0, 0, 0, 25, 0, 0, 0, 81].

2. Programming Flow Control for Conditional and Repetitive Commands 18 FOR statements Repetitive commands (2) Using FOR statements for computing s = 20 i=1 x i

2. Programming Flow Control for Conditional and Repetitive Commands 19 WHILE statements Repetitive commands (1) Using WHILE statements for computing s = 20 i=1 x i

2. Programming Flow Control for Conditional and Repetitive Commands 20 WHILE statements Repetitive commands (2) Using WHILE statements for computing s = 20 i=1 x i

2. Programming Flow Control for Conditional and Repetitive Commands 21 Logical expressions Description of conditions Logical operators assess conditions and return Boolean values (1/0 or True/False).

3. Nonlinear Equation System 22 Direct Substitution Method (Fixed-Point Method) (1) Initialization: Reformulate equation f (x) = 0 as x=g(x). Give an initial guess x 0 and convergence tolerance ε, set k = 0. (2) Iteration k+1: Compute the next candidate solution x k+1 = g(x k ). (3) Termination Check: If x k+1 x k ε, return x k+1 as the numerical solution; Otherwise, k = k +1, and go to (2).

3. Example Implementations 23 Direct substitution Implementation via script or function To start the solution procedure, type in prompt line: To start the solution procedure, type in prompt line:

3. Example Implementations 24 Newton s method (1) Initialization: Give a guess x 0 and tolerances ε,ε a,ε r, set k = 0. (2) Iteration k+1: Compute f(x k ), J k, and x k+1 = x k J 1 k f(x k ). (3) Termination Check: If f(x k ) ε or x k+1 x k x k ε r +ε a, return x k+1 as the numerical solution; Otherwise, k = k +1, and go to (2). Solution information Algorithm initial condition

3. Example Implementations 25 Newton s method Example of function and Jacobian evaluation f(x) = absin(x 1 ) + cos(x 2 ) a ln(x 1 ) + e b2 (x 1 +x 2 ), where a = 1, b = 0.5. J = a x 1 abcos(x 1 ) sin(x 2 ) + b 2 e b 2 (x 1 +x 2 ) b 2 e b2 (x 1 +x 2 ), where a = 1, b = 0.5.

3. Example Implementations 26 Newton s method MATLAB command for execution If initial guess x 0 = x 1,0 x 2,0 = 0.2 2 then the MATLAB command is:, tolerances: ε = 10 6, ε a = 10 6, ε r = 10 6, Note: MATLAB m-files Newton.m, fun.m, Jfun.m need to be included in the current folder for execution of the command!

3. Example Implementations 27 Newton s method Alternative implementation (1) Initialization: Give a guess x 0 and tolerances ε,ε a,ε r, set k = 0. (2) Iteration k+1: Compute f(x k ), J k, and x k+1 = x k J 1 k f(x k ). (3) Termination Check: If f(x k ) ε or x k+1 x k x k ε r +ε a, return x k+1 as the numerical solution; Otherwise, k = k +1, and go to (2).

3. Example Implementations 28 Explicit Euler - From algorithm to a MATLAB function x = f(x), x(0) = x 0 (1) Initialization: Give t 0 (= 0), t f, Δt, set k = 0. (2) Step k +1: m(k) = f(x(k)), x(k +1) = x(k) + m(k)δt (3) Termination Check : If k +1 = n(= t f / Δt), terminate and return [x(1)... x(n)] T ; Otherwise, set k = k +1, go to (2).

3. Example Implementations 29 Explicit Euler - Example of search direction evaluation x 1 = absin(x 1 ) + cos(x 2 ), x 2 = a ln(x 1 ) + e b2 (x 1 +x 2 ), where a = 1, b = 0.5.

3. Example Implementations 30 Explicit Euler - MATLAB command for execution If time period [t 0, t f ] = [0,1], time step Δt = 0.1, initial condition x(0) = x 1 (0) x 2 (0) = 1 1, then the MATLAB command is: Note: MATLAB m-files Euler.m, odefun.m need to be included in the current folder for execution of the command!

3. Example Implementations 31 Explicit Euler - Alternative implementation x = f(x), x(0) = x 0 (1) Initialization: Give t 0 (= 0), t f, Δt, set k = 0. (2) Step k +1: m(k +1) = f(x(k)), x(k +1) = x(k)+ m(k)δt (3) Termination Check : If k +1 = n(= t f / Δt), terminate and return [x(1)... x(n)] T ; Otherwise, set k = k +1, go to (2).