Hydroinformatics: Session4 Dr Ivan Stoianov Room 328B Dr Andrew Ireson (Room 304) Mr Juan Rodriguez-Sanchez (411A) Mr Baback.

Slides:



Advertisements
Similar presentations
Splines and Piecewise Interpolation
Advertisements

MATLAB – A Computational Methods By Rohit Khokher Department of Computer Science, Sharda University, Greater Noida, India MATLAB – A Computational Methods.
Intro to modeling April Part of the course: Introduction to biological modeling 1.Intro to modeling 2.Intro to biological modeling (Floor) 3.Modeling.
259 Lecture 17 Working with Data in MATLAB. Overview  In this lecture, we’ll look at some commands that are useful for working with data!  fzero  sum,
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
1 Eng. Mohamed El-Taher Eng. Ahmed Ibrahim. 2 1.FUNCTION SUMMARY polyfun  Polynomial functions are located in the MATLAB polyfun directory. For a complete.
MATLAB Lecture Two (Part II) Thursday/Friday, July 2003.
CITS2401 Computer Analysis & Visualisation
ES 240: Scientific and Engineering Computation. InterpolationPolynomial  Definition –a function f(x) that can be written as a finite series of power functions.
Transfer Functions Convenient representation of a linear, dynamic model. A transfer function (TF) relates one input and one output: The following terminology.
Part 4 Chapter 13 Linear Regression
CVEN Exam 1 Review. Matlab Basic commands and syntax Basic commands and syntax Creation of functions and programs Creation of functions and programs.
Exam #3 Review: Comprehensive Exam Class 14.2 Palm Matlab Book Ch. 1-5.
Transfer Functions Convenient representation of a linear, dynamic model. A transfer function (TF) relates one input and one output: The following terminology.
ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.
10.1 Gaussian Elimination Method
Arithmetic Operations on Matrices. 1. Definition of Matrix 2. Column, Row and Square Matrix 3. Addition and Subtraction of Matrices 4. Multiplying Row.
Chapter 7 Matrix Mathematics Matrix Operations Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Matrices Write and Augmented Matrix of a system of Linear Equations Write the system from the augmented matrix Solve Systems of Linear Equations using.
Solving Systems of Equations: Elimination Method.
Exercise problems for students taking the Programming Parallel Computers course. Janusz Kowalik Piotr Arlukowicz Tadeusz Puzniakowski Informatics Institute.
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
Systems and Matrices (Chapter5)
ECON 1150 Matrix Operations Special Matrices
THU, JAN 8, 2015 Create a “Big Book of Matrices” flip book using 4 pages. Do not make your tabs big! BIG BOOK OF MATRICES What is a Matrix? Adding & Subtracting.
Section 1.1 Introduction to Systems of Linear Equations.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
1 Week 3: Vectors and Matrices (Part III) READING: 2.2 – 2.4 EECS Introduction to Computing for the Physical Sciences.
MECN 3500 Inter - Bayamon Lecture 9 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
Boundary Value Problems and Least Squares Minimization
Department of Mechanical Engineering, LSU Session IV MATLAB Tutorials Session IV Mathematical Applications using MATLAB Rajeev Madazhy
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.
Goal: Solve a system of linear equations in two variables by the linear combination method.
Introduction to Matlab Module #2 Page 1 Introduction to Matlab Module #2 – Arrays Topics 1.Numeric arrays (creation, addressing, sizes) 2.Element-by-Element.
MATHLAB Prepared for: Md. Monzur Ashraf Prepared By: Md. Shafiul Parvez Aakaash.
Scientific Computing General Least Squares. Polynomial Least Squares Polynomial Least Squares: We assume that the class of functions is the class of all.
Mathematical Applications using MATLAB (Cont….)
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Recap Cubic Spline Interpolation Multidimensional Interpolation Curve Fitting Linear Regression Polynomial Regression The Polyval Function The Interactive.
Polynomials, Curve Fitting and Interpolation. In this chapter will study Polynomials – functions of a special form that arise often in science and engineering.
11/6/ :55 Graphics II Introduction to Parametric Curves and Surfaces Session 2.
MODEL FITTING jiangyushan. Introduction The goal of model fitting is to choose values for the parameters in a function to best describe a set of data.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Chapter 15 General Least Squares and Non- Linear.
ME 142 Engineering Computation I Exam 3 Review Mathematica.
Introduction to MATLAB Session 2 Simopekka Vänskä, THL Department of Mathematics and Statistics University of Helsinki 2010.
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
1. Systems of Linear Equations and Matrices (8 Lectures) 1.1 Introduction to Systems of Linear Equations 1.2 Gaussian Elimination 1.3 Matrices and Matrix.
Recap Functions with No input OR No output Determining The Number of Input and Output Arguments Local Variables Global Variables Creating ToolBox of Functions.
ABE425 Engineering Measurement Systems Ordinary Least Squares (OLS) Fitting Dr. Tony E. Grift Dept. of Agricultural & Biological Engineering University.
ERT 210/4 Process Control & Dynamics DYNAMIC BEHAVIOR OF PROCESSES :
1 Lecture 8 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Finishing up Chapter 5. Will this code enter the if statement? G=[30,55,10] if G
Determinants Every n  n matrix A is associated with a real number called the determinant of A, written  A . The determinant of a 2  2 matrix.
Chapter 5: Matrices and Determinants Section 5.5: Augmented Matrix Solutions.
An Introduction to Matrix Algebra Math 2240 Appalachian State University Dr. Ginn.
Introduction to Programming for Mechanical Engineers
Transfer Functions Convenient representation of a linear, dynamic model. A transfer function (TF) relates one input and one output: The following terminology.
EEE 244-7: Curve Fitting.
Salinity Calibration fit with MATLAB
Class Notes 8: High Order Linear Differential Equation Non Homogeneous
MATH My research interests lie primarily in the area of numerical analysis and scientific computing, …
Chapter 4 Systems of Linear Equations; Matrices
Nonlinear regression.
Communication and Coding Theory Lab(CS491)
Chapter 1: Linear Equations in Linear Algebra
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.
Chapter 4 Systems of Linear Equations; Matrices
Presentation transcript:

Hydroinformatics: Session4 Dr Ivan Stoianov Room 328B Dr Andrew Ireson (Room 304) Mr Juan Rodriguez-Sanchez (411A) Mr Baback Mirshahi (304) Mx Max Kigobe (304)

Hydroinformatics: Matlab Session 1: Introduction to Hydroinformatics & Basic Matlab Use Session 2: Working with Arrays and Graphics. Curve Fitting & Interpolation Session 3: Script Files & Functions Session 4: Script & Functions & Data Analysis (Stats), ODEs & Nonlinear Algebraic Equations Session 5: Matlab Symbolic Mathematics

Few Reminders Array Operations -Eliminates the need for FOR LOOP Exercise: Compute the product of data in two columns, x and y, where each column has n entries n=5 X – linearly spaced vector of 5 points between 10 to 20; Y – linearly spaced vector of 5 points between 20 to 40; - Compute the product of X * Y using a FOR LOOP - Any other way using a single line of code? array_test.m

Few Reminders Matrix Operations Element-by-element multiplications Matrix product Two FOR LOOPS: row index column index

Few Reminders Matrix Operations Exercise: Multiply two matrices – create a script called matrix_test n=5 x(5,5) x1 – linearly spaced vector of 5 points between 1 to 5; x2=x1+2 x3=x1+3 x4=x1+4 x5=x1+5 x=[x1; x2; x3; x4; x5]; Y(5,5) y1 – linearly spaced vector of 5 points between 5 to 9; y2, y3, y4, y5 – same procedures as X - Compute the product of X(5,5) and Y(5,5) using a FOR LOOP computation (DOUBLE LOOP) - Any other way using a single line of code? matrix_test.m

Please note Array  dot product! Matrix  No worries re DOT product if A & B are compatible VECTORIZATION Take full advantage of array operations by vectorizing your code or computation

Exercise: vectorization Approximate the exponential function with the first 10 terms in its series expansion: Assume: x=1; k=[1:10] Sum Factorial Vectorization./ vectorization_test.m

Session #3: Script & Functions Script: Write a script to solve the following system of linear equations -Find a solution of the equation for various values of the parameter r -Find the determinant of matrix A in each case solvex.m

Function files - Same as a script file, except that the variables in a function file are all local -Starts with a function definition line + a well defined list of inputs and outputs function [output variables]=function_name (input variables); -function_name can be the same as file name; -function must be typed in lower case (NOT Function) -Comment: function_test.m function_test.m

Function files: Executing a function % function definition line function [rho,H,F]=motion (x,y,t); ??? How do we execute the function (function call execution statements) 5 mins to write as many as possible in a script file rt, yt, timeR, angmon, force rx,ry, [0:100]r,h,f 2, 3.5, 0.001r,h,f rx,ryradius, h Input variablesOutput variables function_test2.m

Session #3: Script & Functions Function: Turn your script into a a function -Find a solution of the equation for various values of the parameter r -Find the determinant of matrix A in each case solvexf.m

Follow-up from Session #4 -Solving a set of linear algebraic equations -Curve fitting -Least squares fitting (an optimization problem) -Data Analysis and stats -Ordinary Differential Equation (ODEs)

Applications Solving a set of linear algebraic equations (1) Write equations in matrix form (2) Solve the matrix equation in Matlab (3) Check the solution (4) Write a function solvexf2 {output x}

Curve Fitting Built-in polynomial functions  Desired coefficients polyfit: a=polyfit(x,y,n) polyval

Linear fit M: Compute spring force: F=m/1000*g [N] Deformation: (1) Find the coefficients a=polyfit (x,y,1) (2) Evaluate y at finer xjs using the fitted polynomial y_fitted=polyval (a,x_fine) (3) Plot and see plot(x,y,’o’,x_fine,y_fitted); linefit_test.m

Least squares curve fitting Polynomial Non-Polynomial

Steps: (1)Prepare new data by taking the log of the original data ybar=log(y) Leave x as it is (2) Do a linear fit: use polyfit to find the coefficients a0 and a1 (3) Plot the curve: from the curve fit coefficients, calculate the values of the original constants t: 0; 0.5; 1.0; 5.0; 10.0; 20.0 P 760, 625, 528, 85, 14, 0.16 nonlinfit.m

Least squares curve fitting

Interpolation Interp1 YI = INTERP1(X,Y,XI) interp2; interp3; spline Exercise: X: 0, 0.785, 1.570, 2.356, 3.141, 3.927, 4.712, Y: 0, 0.707, 1.000, 0.707, 0.000, , , , 0 exinterp.m

Data Analysis and Statistics X=[ ] A=[6, 5, -2; 7, 4, -1; 8, 3, 0; 9, 2, 1; 10, 2,2] Find: mean; median; std; max; min; sum; cumsum; prod; sort; sortrows; trapz;

Ordinary Differential Equations ode23 & ode45: most popular Implementation of second/third order and fouth/fifth order Runge-Kutta methods Basic rules: -Write the differential equations as a set of first order ODEs -- write a function to compute the state derivative (the vector of derivatives) -- use the built-in ODE solvers to solve the equations

ODEs [time, solution] = ode23(‘your function’, tspan, x0) YourFunction  user written function with title line: xdot=YourFunction(t,x). This function contains the ODEs you want to solve

ODE Example: