Using MatLab and Excel to Solve Building Energy Simulation Problems Jordan Clark

Slides:



Advertisements
Similar presentations
Adding & Subtracting Matrices
Advertisements

Intro to modeling April Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.
Differential Equations Math Review with Matlab: Finding Solutions to Differential Equations S. Awad, Ph.D. M. Corless, M.S.E.E. D. Cinpinski E.C.E. Department.
Linear Algebra Applications in Matlab ME 303. Special Characters and Matlab Functions.
Section 2.1 Solving Linear Equations
Chapter 4 Systems of Linear Equations; Matrices Section 2 Systems of Linear Equations and Augmented Matrics.
1 Systems of Linear Equations & Matrices Sections 4.2 & 4.3 After today’s lesson, you will be able to Use terms associated with matrices. Set up and solve.
Chapter 4 Systems of Linear Equations; Matrices Section 6 Matrix Equations and Systems of Linear Equations.
Chapter 1 Computing Tools Data Representation, Accuracy and Precision Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction.
Chapter 2 Section 1 Solving a System of Linear Equations (using Matrices)
Matlab Matlab is a powerful mathematical tool and this tutorial is intended to be an introduction to some of the functions that you might find useful.
Matrix Mathematics in MATLAB and Excel
Using Matrices to Solve a 3-Variable System
HAWKES LEARNING SYSTEMS math courseware specialists Copyright © 2011 Hawkes Learning Systems. All rights reserved. Hawkes Learning Systems College Algebra.
Using Matrices to Solve a System of Equations. Multiplicative Identity Matrix The product of a square matrix A and its identity matrix I, on the left.
Warm-Up Solving Systems of Equations Learning Targets l Refresher on solving systems of equations l Matrices –Operations –Uses –Reduced Row Echelon.
Functions 1 parameter, 2 return-values "Conversion of time format" One problem. 5 steps to solve it. 1.
THE MATLAB ENVIRONMENT VARIABLES BASIC COMMANDS HELP HP 100 – MATLAB Wednesday, 8/27/2014
Algebraic Expressions
4.4 & 4.5 Notes Remember: Identity Matrices: If the product of two matrices equal the identity matrix then they are inverses.
4.6 Matrix Equations and Systems of Linear Equations In this section, you will study matrix equations and how to use them to solve systems of linear equations.
Section 3.6 – Solving Systems Using Matrices
CMPS 1371 Introduction to Computing for Engineers MATRICES.
Converting Fractions to Decimals
MATLAB Basics. The following screen will appear when you start up Matlab. All of the commands that will be discussed should be typed at the >> prompt.
Unit 3: Matrices.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Definition A mathematical sentence, that shows that two expressions, either numerical or algebraic, are equivalent. Like a balance. Characteristics Isolate.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Getting Started with MATLAB (part2) 1. Basic Data manipulation 2. Basic Data Understanding 1. The Binary System 2. The ASCII Table 3. Creating Good Variables.
Working with Arrays in MATLAB
ME 142 Engineering Computation I Matrix Operations in Excel.
A (VERY) SHORT INTRODUCTION TO MATLAB J.A. MARR George Mason University School of Physics, Astronomy and Computational Sciences.
3.6 Solving Systems Using Matrices You can use a matrix to represent and solve a system of equations without writing the variables. A matrix is a rectangular.
ME 142 Engineering Computation I Matrix Operations in Excel.
CSE 2813 Discrete Structures Solving Recurrence Relations Section 6.2.
Warm- Up Solve the following systems using elimination or substitution : 1. x + y = 6 -3x + y = x + 4y = 7 x + 2y = 7.
Section 3.2 Solving Equations using Multiplication and Division.
4.8 Using matrices to solve systems! 2 variable systems – by hand 3 or more variables – using calculator!
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Finishing up Chapter 5. Will this code enter the if statement? G=[30,55,10] if G
Warm Up Multiply the matrices. 1. Find the determinant. 2. –1 Welcome! I’m so glad you’re here! Please get your Calculator. Please get started on this.
Unit 3: Matrices. Matrix: A rectangular arrangement of data into rows and columns, identified by capital letters. Matrix Dimensions: Number of rows, m,
Chapter 5: Matrices and Determinants Section 5.5: Augmented Matrix Solutions.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 3 - Chapter 8 Linear Algebraic Equations and Matrices.
Chapter 1 Computing Tools Variables, Scalars, and Arrays Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Solving Inequalities using addition or subtraction and Multiplication or division.
Using Matrices to Solve a 3-Variable System
Downhill product – Uphill product.
Use Inverse Matrices to Solve Linear Systems
Systems of Linear Equations: Matrices
3-5 More on Solving Equations
Solving Linear Systems Syed Nasrullah
L9Matrix and linear equation
Matrix Equations Step 1: Write the system as a matrix equation. A three-equation system is shown below. First matrix are the coefficients of all the.
Other Kinds of Arrays Chapter 11
HW2 Example MatLab Code is posted on the course website
Warm Up Use scalar multiplication to evaluate the following:
Use Inverse Matrices to Solve Linear Systems
Lecture Objectives: Analysis of unsteady state heat transfer HW3.
Use Inverse Matrices to Solve 2 Variable Linear Systems
Unit 3: Matrices
Matrix Solutions to Linear Systems
Linear Algebra Lecture 3.
Solving Equations involving Decimal Coefficients
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
1.11 Use Inverse Matrices to Solve Linear Systems
Bell Ringer Solve the following: 1. ) 7(4 – t) = -84 2
Solving Linear Systems of Equations - Inverse Matrix
Presentation transcript:

Using MatLab and Excel to Solve Building Energy Simulation Problems Jordan Clark

Objectives Intro to MatLab (if needed) Briefly discuss linear equations Solving systems of non-linear equations – Using solve function Example 1 – Using loops to solve for multiple time steps Example 2 – Importing data from Excel Example 3

Linear Equations in MATLAB Solve system of equations: 3x +2y –z = 10 -x +3y +2z = 5 x -y -z = -1

Linear Equations in MATLAB

3 ways to solve in MATLAB: – Inv – A^-1 – Left division

Linear Equations in MATLAB For all three, first define matrices: A= [3 2 -1; ; ]; B= [10; 5; -1]; Can be solved by any of the following syntaxes: X=inv(A)*B X=A^-1*B X=A\B NOT X=A/B or X=B\A Each gives equivalent answer Left division is more computationally efficient: less time to compute for large matrices

Non-Linear Equations in MATLAB Distinguish between symbolic variables (ones you will solve for) and variables with numeric values (i.e. , F 12, etc.) Define symbolic variables: – Can create multiple symbolic variables at once with syms command – Syntax: syms x y z a b c or syms T1 T2 T3

Non-Linear Equations in MATLAB Say we have defined symbolic variable x and want to solve an equation for x. With symbolic variables defined, create equation using syntax: E1=x-3 Notice your equation must be in the form f(x)=0 If it is not, rearrange it so it is

Non-Linear Equations in MATLAB We can now use solve function to find x: If we just write solve (E1) we will get ans = 3 If we want to redefine x as the solution, we can input x= solve(E1)

Non-Linear Equations in MATLAB For systems of equations, process is similar. – Define variables using syms – Write multiple homogeneous equations e.g. E1= x + y + z +2 E2= 3*x -2*y + z E3= -x + y -4*z +6 – Then use [x,y,z]=solve(E1, E2, E3) – Variables must be listed in alphabetical order on left side because right side outputs answers in alphabetical order of symbolic variables

Non-Linear Equations in MATLAB Sometimes you will be working with both symbolic and numerical variables. This is ok.

Non-Linear Equations in MATLAB Example 1: Find both T 2 and Q for the steady state conduction problem, given k=4W/mK, wall thickness is 0.2m, T 1 =30, T 3 =40, and the area of the wall is 4m 2 T1T1 T2T2 T3T3 Q

Non-Linear Equations in MATLAB Example 1 Code: k=4; %W/mK A=4; %m^2 L=0.1; %m T1=30; %degrees C T3=40; syms Q T2; E1= k*A/L*(T3-T2)-Q; E2= k*A/L*(T2-T1)-Q; [Q, T2]=solve(E1, E2) Output: Q = 800 T2 = 35

Non-Linear Equations in MATLAB Example 2: Using a loop to solve for multiple time steps Now suppose the temperature of the outside wall changes every hour, in discrete jumps (steady state assumption can be used for each hour) We need an efficient means of calculating T 2 and Q for each hour Will use a loop

Non-Linear Equations in MATLAB Say we are given this data for the outside temperature, T 3 : and we want to find T 2 and Q at each time TimeT3 12 midnight noon41

Non-Linear Equations in MATLAB Example 2 1 st create an array with the temperatures: T3=[ ] Then loop through each value of T3 to calculate a corresponding value of Q and T2, and store these values in a Q and T2 array

Non-Linear Equations in MATLAB Example 2 code: k=4; %W/mK A=4; %m^2 L=0.1; %m T1=30; %degrees C T3=[ ]; %input temperature array syms Q T2; % define symbolic variables for i=1:13 % tells the program to loop through 13 iterations % (corresponding to 13 hours for which we have data) E1= k*A/L*(T3(i)-T2)-Q; %notice an individual value of the data is called for T3 E2= k*A/L*(T2-T1)-Q; %by using the index "i" in T3(i) [Qarray(i), T2array(i)]=solve(E1, E2) %we save our data in a separate array, % which is appended automatically each iteration end T2array=double(T2array) %when doing symbolic math, answer is often returned in fractional form. %to convert it to decimal form, use the function "double", as in double precision

Non-Linear Equations in MATLAB Example 2: Qarray= Output: T2array=

Non-Linear Equations in MATLAB Example 3: Importing Data from Excel Sometimes we have a lot of data and cannot input it by hand, e.g. TMY data There are a few ways to import data from Excel – Cut and paste – Use import wizard by selecting File > Import Data or Use function uiimport When using the wizard, make sure the file is saved in your working directory

Non-Linear Equations in MATLAB Example 3 Say we now are not given T 3, but we have an outdoor convection coefficient, h, which changes with time, and an outdoor air temperature. T 1 =30 T2T2 T3T3 Q T out We want to find all T values and Q using the import wizard

Non-Linear Equations in MATLAB Example 3: Importing Data from Excel Here is the data we have, in a worksheet by itself: If we just use the wizard, a 13x3 matrix is created, with the name of the Excel file (I called mine tdata) Time (h)Tout (C)h (W/m^2-K)

Non-Linear Equations in MATLAB Example 3: Importing Data from Excel We can make separate arrays if we like for each variable by using commands such as >> Tout=tdata (:,2) %which says the array “Tout” is the 2 nd column of “tdata” Tout =

Non-Linear Equations in MATLAB Example 3: Importing Data from Excel Once we identify the h values in a similar way, we can solve our problem Code on next slide

Non-Linear Equations in MATLAB Example 3 Code k=4; %W/mK A=4; %m^2 L=0.1; %m T1=30; %degrees C syms Q T2 T3; for i=1:13 E1= k*A/L*(T3-T2)-Q; E2= k*A/L*(T2-T1)-Q; %we now have 3 eqns + 3 unknowns E3= h(i)*A*(Tout(i)-T3)-Q; %notice indices on h and Tout [Qarray(i), T2array(i), T3array(i)]=solve(E1, E2, E3) end Qarray=double(Qarray)' T2array=double(T2array)' T3array=double(T3array)'

Non-Linear Equations in MATLAB Example 3 Output Qarray = T2array = T3array =

Conclusion Should be everything you need to finish homework Additional help (2 equation model form the class) on the course website, handouts section Please contact me with questions about Matlab or about B.E.S. Questions now????