Recap Cubic Spline Interpolation Multidimensional Interpolation Curve Fitting Linear Regression Polynomial Regression The Polyval Function The Interactive.

Slides:



Advertisements
Similar presentations
MathCAD Data.
Advertisements

Chapter 18 Interpolation The Islamic University of Gaza
CITS2401 Computer Analysis & Visualisation
By Hrishikesh Gadre Session II Department of Mechanical Engineering Louisiana State University Engineering Equation Solver Tutorials.
Curve-Fitting Interpolation
MathCAD Data. Data in tables Tables are analogous to matrix The numbers of columns and rows can be dynamically changed (in contrast to matrix) To enter.
Part 6 Chapter 22 Boundary-Value Problems PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The McGraw-Hill.
ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW III.
Chapter 6 Numerical Interpolation
Differential Equations
Derivatives and Differential Equations
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Numerical Differentiation and Integration Part 6 Calculus.
EPSII 59:006 Spring Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops.
Introduction  Today we are looking at how to interpret experimental data  Normally, data is acquired with random errors  How do we take the data and.
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically.
Ch 8.1 Numerical Methods: The Euler or Tangent Line Method
Chapter 9 Introduction to MATLAB for Engineers, Third Edition
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
DIFFERENTIAL EQUATIONS, INTEGRATION, POLYNOMIALS, RANDOM NUMBERS MEKANIKA SOFTWARE SEMINARS.
Chapters 5 and 6: Numerical Integration
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
1 Tips for solving Project 1 Reactor SO 3 SO 2 +O 2.
Curve Fitting and Interpolation: Lecture (I)
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Curve Fitting.
Hydroinformatics: Session4 Dr Ivan Stoianov Room 328B Dr Andrew Ireson (Room 304) Mr Juan Rodriguez-Sanchez (411A) Mr Baback.
Recap Summary of Chapter 6 Interpolation Linear Interpolation.
Curve Fitting and Regression EEE 244. Descriptive Statistics in MATLAB MATLAB has several built-in commands to compute and display descriptive statistics.
Department of Mechanical Engineering, LSU Session IV MATLAB Tutorials Session IV Mathematical Applications using MATLAB Rajeev Madazhy
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Chapter 4 "Inheritance" Inheritance is a powerful feature that allows the reuse of code. However, be sure that functions applied to objects created at.
ES 240: Scientific and Engineering Computation. Chapter 13: Linear Regression 13. 1: Statistical Review Uchechukwu Ofoegbu Temple University.
MATHLAB Prepared for: Md. Monzur Ashraf Prepared By: Md. Shafiul Parvez Aakaash.
The elements of higher mathematics Differential Equations
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 6 - Chapter 24 Boundary Value Problems.
Beginning Programming for Engineers
Mathematical Applications using MATLAB (Cont….)
The Islamic University of Gaza Faculty of Engineering Civil Engineering Department Numerical Analysis ECIV 3306 Introduction Course Outline.
Modelling & Simulation of Chemical Engineering Systems Department of Chemical Engineering King Saud University 501 هعم : تمثيل الأنظمة الهندسية على الحاسب.
Recap Saving Plots Summary of Chapter 5 Introduction of Chapter 6.
6.094 Introduction to programming in MATLAB Danilo Šćepanović IAP 2008 Lecture 3 : Solving Equations and Curve Fitting.
Analyzing Functions (4.16) y=f(x) MATLAB. Functional Analysis includes: Plotting and evaluating a function Finding extreme points Finding the roots (zeros.
Ordinary Differential Equations (ODEs) 1Michael Sokolov / Numerical Methods for Chemical Engineers / Explicit ODE Solvers Michael Sokolov ETH Zurich, Institut.
Numerical Analysis 3D Plots. A numerical method is a technique for computing a numerical approximation of the solution to a mathematical problem.
Jump to first page Chapter 3 Splines Definition (3.1) : Given a function f defined on [a, b] and a set of numbers, a = x 0 < x 1 < x 2 < ……. < x n = b,
Chapter 10 ordinary differential equations (ODEs) Chapter 11 systems of ODEs (6 th edition)
Polynomials, Curve Fitting and Interpolation. In this chapter will study Polynomials – functions of a special form that arise often in science and engineering.
Intro to Simulink April 15, Copyright , Andy Packard. This work is licensed under the Creative Commons.
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.
Chapter 13 Objectives Familiarizing yourself with some basic descriptive statistics and the normal distribution. Knowing how to compute the slope and intercept.
Recap Functions with No input OR No output Determining The Number of Input and Output Arguments Local Variables Global Variables Creating ToolBox of Functions.
ECE 576 – Power System Dynamics and Stability Prof. Tom Overbye Dept. of Electrical and Computer Engineering University of Illinois at Urbana-Champaign.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 5 Integration and Differentiation.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
ACSL, POSTECH1 MATLAB 입문 CHAPTER 8 Numerical Calculus and Differential Equations.
Intro to Simulink Modified by Gary Balas 20 Feb 2011 Copyright , Andy Packard. This work is licensed under.
1 Lecture 8 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Chapter 17 and 18 Interpolation.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 6 - Chapters 22 and 23.
MATLAB ® for Engineers, Holly Moore Fourth Edition, Global Edition © Pearson Education Limited 2015 All rights reserved. Figure 13.1 Interpolation between.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 21 Numerical Differentiation.
Lecture 29: Modeling Data. Data Modeling Interpolate between data points, using either linear or cubic spline models Model a set of data points as a polynomial.
CMPSC 200 Fall 2013 Lecture 37 November 18, 2013.
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Introduction to Programming for Mechanical Engineers
Introduction to Programming for Mechanical Engineers
Lecture 25.
Advanced Numerical Methods (S. A. Sahu) Code: AMC 51151
User Defined Functions
Presentation transcript:

Recap Cubic Spline Interpolation Multidimensional Interpolation Curve Fitting Linear Regression Polynomial Regression The Polyval Function The Interactive Fitting Tools Basic Curve Fitting Curve Fitting ToolBox Numerical Integration

Numerical Integration Example Here’s another example, using a function handle and an anonymous function, instead of defining the function inside single quote First define an anonymous function for a third-order polynomial fun_handle Now plot the function, to see how it behaves. The easiest approach is to use fplot, since it also accepts a function handle: fplot(fun_handle,[-5,25])

Example Continued….

Solving Differential Equation Numerically

Continued…. Each solver requires the following three inputs as a minimum: A function handle to a function that describes the fi rst-order differential equation or system of differential equations in terms of t and y The time span of interest An initial condition for each equation in the system The solvers all return an array of t- and y -values: [t,y] = odesolver(function_handle,[initial_time, final_time], [initial_cond_array]) If the resulting arrays [t,y] are not specified, the functions create a plot of theresults

Function Handle Input

Continued….

Solving the Problem

Continued….

When the input function or system of functions is stored in an M-file, the syntax is slightly different The handle for an existing M-file is defined To solve the system of equations described in twofun we use the command The time span of interest is from -1 to 1, and the initial conditions are both 1

Solving Higher-Order Differential Equations

Continued…. Now all we need to do is create an M-file function to use in one of the ode solvers The function should have two inputs, which are typically called t and y The variable t is the independent variable, and the variable y is an array of dependent variables In this example y (1) corresponds to the y used in the hand formulation, and y (2) corresponds to z The function containing the system of equations should look like this: function dydt = twoeq(t,y) dydt(1) = y(2); dydt(2) = y(1) + t - dydt(1); dydt = dydt' Notice that the function output has been formulated as a column vector, as required by the ode solvers Also recall that the function name is arbitrary. We could have called it anything, but twoeq is descriptive

Continued…. Once the system of equations is defined in a function M- file it is available to use as input to an ode solver For example: if the range of time is defined as -1 to +1 and the initial conditions are defined as y = 0 and z=0, then the command becomes which gives the results A problem where the starting values are known is called an initial value problem

Boundary Value Problems bvp4c function is used to solve boundary value problems The bvp4c function requires three inputs: A function handle to the system of ode’s to be solved A function handle to a function that solves for the residual values of the function A set of guesses for the initial conditions

Continued…. The first function handle is exactly the same as we used for the ode solver set of functions It should contain the equations for the derivatives of interest and the results must be a column vector To solve the problem a guess is made for the initial value of all the derivatives, then the program checks to see how it did by comparing the calculated boundary values with the actual values For example, if: at t = -1, y = 0 and at t = 1, y = 3 the program would solve the system of equations based upon an initial guess of d y /d t, and would then check to see how close the result is at t = -1 This is accomplished using a boundary condition function where the equations are arranged so that if the correct boundary condition is calculated, the function values are zero In the case of our example, function residual=bc(y_initial, y_final) residual(1) = y_initial(1) + 0; residual(2) = y_final (1) - 3; residual = residual';

Continued…. If this function is executed for values of y_initial = 0 and y_final = 3, the result will be a column of zeros Any other result means that the program has calculated the wrong values for y_initial and y_final, and the guesses for the initial conditions must be updated according to the function’s algorithm, which is a finite difference strategy

Continued…. The last input to the bvp4c function is a mesh of guesses for the problem solution, which are used as the starting point in the solution MATLAB provides a helper function, bvpinit, to help create this mesh, which is stored as a structure array It requires two inputs; an array of values corresponding to the independent variable initial guesses for each of the variables defined in the ode system of equations In our case there are two equations, so we’ll need a guess for y and d y /d t The mesh need not be particularly fi ne, and the initial guesses need not be very good For example: initial_guess = bvpinit(-1:.5:1, [0, -1]) specifies five t values from -1 to 1 (-1, -0.5, 0, 0.5, 1) and initial guesses of y = 0 and dydt = -1 at all values of t

Continued…. Once the function describing the system of ode’s, the function defining the residuals and the initial guesses created with bvpinit have been created, the bvp4c function can be initial_guess) which returns ans = x: [1x9 double] y: [2x9 double] yp: [2x9 double] solver: 'bvp4c' The result is a structure array, where x is the value of the independent variable and where an array of y values corresponds to the solutions to the system of ode’s. In this case, y and dy /dt. To access the array of x values simply use the structure syntax, ans.x If we had chosen to assign a name such as solution to our result instead of defaulting to ans, the structure would be called solution, and the x values would be stored in solution.x The values of most interest are the y values, which can also be accessed using structure syntax, such as solution.y To plot the results in a manner similar to that displayed by the odesolvers use the code plot(ans.x,ans.y, '-o') or, if the results were named solution plot(solution.x, solution.y, '-o'), which gives the results

Summary of Chapter Tables of data are useful for summarizing technical information However, if a value is needed that is not included in the table, must approximate that value by using some sort of interpolation technique MATLAB includes such a technique, called interp1. This function requires three inputs: a set of x -values, a corresponding set of y -values, and a set of x -values for which you would like to estimate y -values The function defaults to a linear interpolation technique, which assumes that approximate these intermediate y -values as a linear function of x that is, y = f(x) = ax + b

Continued…. A different linear function is found for each set of two data points, ensuring that the line approximating the data always passes through the tabulated points The interp1 function can also model the data by using higher-order approximations, the most common of which is the cubic spline The approximation technique is specified as a character string in a fourth optional field of the interp1 function If it’s not specified, the function defaults to linear interpolation. An example of the syntax is new_y = interp1(tabulated_x, tabulated_y, new_x, 'spline')

Continued…. In addition to the interp1 function, MATLAB includes a two- dimensional interpolation function called interp2, a three- dimensional interpolation function called interp3, and a multidimensional interpolation function called interpn Curve-fitting routines are similar to interpolation techniques However, instead of connecting data points, they look for an equation that models the data as accurately as possible Once you have an equation, you can calculate the corresponding values of y The curve that is modeled does not necessarily pass through the measured data points MATLAB’s curve-fitting function is called polyfit and models the data as a polynomial by means of a least-squares regression technique

Continued….

MATLAB also includes an interactive curve-fitting capability that allows the user to model data not only with polynomials, but with more complicated mathematical functions The basic curve-fitting tools can be accessed from the Tools menu in the figure window More extensive tools are available in the curve-fitting toolbox, which is accessed by typing cftool in the command window. Numerical techniques are used widely in engineering to approximate both derivatives and integrals Derivatives and integrals can also be found with the symbolic toolbox The MATLAB diff function finds the difference between values in adjacent elements of a vector By using the diff function with vectors of x - and y -values, we can approximate the derivative with the command slope = diff(y)./diff(x) The more closely spaced the x and y data are, the closer will be the approximation of the derivative

Continued…. The gradient function uses a forward difference approach to approximate the derivative at the first point in an array It uses a backward difference approach for the final value in the array, and a central difference approach for the remainder of the points In general, the central difference approach gives a more accurate approximation of the derivative than either of the other two techniques Integration of ordered pairs of data is accomplished using the trapezoidal rule, with the trapz function This approach can also be used with functions, by creating a set of ordered pairs based on a set of x values and the corresponding y values

Continued….

MATLAB includes a series of solver functions for first-order ordinary differential equations and systems of equations All of the solver functions use the common format [t,y] = odesolver(function_handle,[initial_time, final_time], [initial_cond_array]) A good first try is usually the ode45 solver function, which uses a Runge–Kutta technique Other solver functions have been formulated for stiff differential equations and implicit formulations The ode solver functions require that the user know the initial conditions for the problem If, instead, boundary conditions are known at other than the starting conditions, the bvp4 function should be used