Introduction to Programming for Mechanical Engineers

Slides:



Advertisements
Similar presentations
MathCAD Data.
Advertisements

Part 2 Chapter 6 Roots: Open Methods
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 Eng. Mohamed El-Taher Eng. Ahmed Ibrahim. 2 1.FUNCTION SUMMARY polyfun  Polynomial functions are located in the MATLAB polyfun directory. For a complete.
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.
Lecture 11 Chap. 15. Outline Interpolation – Linear Interpolation – Cubic Spline Interpolation – Extrapolation 15.2 Curve.
MATLAB EXAMPLES Interpolation and Integration 58:111 Numerical Calculations Department of Mechanical and Industrial Engineering.
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 4 Chapter 13 Linear Regression
Numerical Operations S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: Polynomial Manipulations.
Properties of Logarithms
Physics 114: Lecture 17 Least Squares Fit to Polynomial
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.
CpE- 310B Engineering Computation and Simulation Dr. Manal Al-Bzoor
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
Introduction to MATLAB for Engineers, Third Edition Chapter 6 Model Building and Regression PowerPoint to accompany Copyright © The McGraw-Hill Companies,
Curve Fitting and Interpolation: Lecture (I)
Lesson 8-1 Multiplying Monomials. Mathematics Standards -Number, Number Sense and Operations: Explain the effects of operations such as multiplication.
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.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
MECN 3500 Inter - Bayamon Lecture 9 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
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.
Curve Fitting and Regression EEE 244. Descriptive Statistics in MATLAB MATLAB has several built-in commands to compute and display descriptive statistics.
Polynomial Interpolation You will frequently have occasions to estimate intermediate values between precise data points. The function you use to interpolate.
Advanced Topics- Polynomials
Department of Mechanical Engineering, LSU Session IV MATLAB Tutorials Session IV Mathematical Applications using MATLAB Rajeev Madazhy
Chapter 14 Curve Fitting : Polynomial Interpolation Gab Byung Chae.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Algebra 1 Notes: Lesson 8-5: Adding and Subtracting Polynomials.
ES 240: Scientific and Engineering Computation. Chapter 13: Linear Regression 13. 1: Statistical Review Uchechukwu Ofoegbu Temple University.
Lecture 10 2D plotting & curve fitting Subplots Other 2-D Plots Other 2-D Plots Curve fitting © 2007 Daniel Valentine. All rights reserved. Published by.
Algebra 1 Notes Lesson 7-4 Elimination Using Multiplication.
LINEAR ALGEBRA Matrix analysis Linear equations Eigenvalues and singular values Matrix functions.
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.
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.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Basis of Mathematical Modeling LECTURE 3 Numerical Analysis with MATLAB Dr. N.K. Sakhnenko, PhD, Professor Associate.
Recap Functions with No input OR No output Determining The Number of Input and Output Arguments Local Variables Global Variables Creating ToolBox of Functions.
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.
STROUD Worked examples and exercises are in the text PROGRAMME F3 EXPRESSIONS and EQUATIONS.
I am able to solve a quadratic equation using complex numbers. I am able to add, subtract, multiply, and divide complex numbers. Solve the equation.
STROUD Worked examples and exercises are in the text 1 STROUD Worked examples and exercises are in the text Programme F3: Expressions and equations PROGRAMME.
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.
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Matlab Training Session 11: Nonlinear Curve Fitting
EEE 244-3: MATRICES AND EQUATION SOLVING
Thinking Mathematically
EEE 244-7: Curve Fitting.
Salinity Calibration fit with MATLAB
Polynomial Interpolation
The Simple Linear Regression Model: Specification and Estimation
Two-Dimensional Plots
Lecture 10 2D plotting & curve fitting
MATH 2140 Numerical Methods
Lesson 2.1 How do you compare positive and negative numbers?
MatLab – Palm Chapter 5 Curve Fitting
Least Squares Fitting A mathematical procedure for finding the best-fitting curve to a given set of points by minimizing the sum of the squares of the.
Unit 4 Mathematics Created by Educational Technology Network
Splines and Piecewise Interpolation
EEE 244-3: MATRICES AND EQUATION SOLVING
SKTN 2393 Numerical Methods for Nuclear Engineers
Approximation of Functions
Theory of Approximation: Interpolation
Presentation transcript:

Introduction to Programming for Mechanical Engineers Lecture 8.1

Things you should have known so far! Write long programming codes with many conditions and loops. Disband the complicated problems into smaller segments and gear them up to integrate the whole process. You should have built the proper tools to help in tackling most of the problems.

Polynomials polynomial MATLAB expression MATLAB recognizes polynomials when entered as arrays. For instance, x^3 + 3*x^2 -7*x + 10 can be entered as [1 3 -7 10]. By default, MATLAB calculates the order of the polynomial by finding the number of elements of the input array. In this example, the number of elements is 4, so the order is 4-1 = 3, which is x^3. polynomial MATLAB expression p1 = [1 -2 0 5] p2 =[-2 0 1 0 5] p3 =[1 -2 5 -1 5 -4 8]

Polynomials evaluation: polyval MATLAB also helps in evaluating the polynomial at certain points. The command polyval(p,x) is useful in evaluating the polynomial (defined by the array of coefficients p) at points given in x (could be single or multiple points). polynomial p Evaluation p1 = [1 -2 0 5] >> polyval(p1,2) ans = 5 p2 = [-2 0 1 0 5] >> polyval(p2,[1 2 -3]) 4 -23 -148 p3 = [1 -2 5 -1 5 -4 8] >> polyval(p3,p1) 12 252 8 12488

Roots of polynomials: roots MATLAB also helps in finding the roots of polynomials. The command roots(p) finds all the roots of the polynomial whose coefficients are defined in p. polynomial p Evaluation p1 = [1 -2 0 5] >> r1 = roots(p1) r1 = 1.6209 + 1.1826i 1.6209 - 1.1826i -1.2419 p2 = [-2 0 1 0 5] >> r2 = roots(p2) r2 = -1.3604 1.3604 1.1622i -1.1622i

Polynomial of roots: poly MATLAB also helps in finding the polynomials of roots. The command poly(r) finds the coefficients of the polynomial whose roots are defined in the array r. roots p polynomial r1 = [ 1.6209 + 1.1826i 1.6209 - 1.1826i -1.2419] >> p1 = poly(r1) p1 = 1.00 -2.00 0.00 5.00 r2 = [-1.3604 1.3604 1.1622i -1.1622i] >> p2 = poly(r2) p2 = 1.00 0.00 -0.50 0.00 -2.50

Polynomials addition, subtr., multip., and division MATLAB is very useful in handling polynomials and performing all kinds of mathematical operations on them. You can add polynomials, subtract, multiply or divide them. Define x = [1 0 3], y = [1 1 -4 3] Operation Command Result Addition Subtraction >> A = y + [0 x] >> B = y - [0 x] A = 1 2 -4 6 B = 1 0 -4 0 Multiplication >> C = conv(x,y) C = 1 1 -1 6 -12 9 Division >> [D E] = deconv(y,x) D = 1 1 (D - quotient) E = 0 0 -7 0 (E - remainder)

Polynomials derivation: polyder MATLAB can find the derivative of polynomials, product of polynomials, and most importantly the division of polynomials using polyder. Define f1 = [1 -1 3 2]; f2 = [3 6 -10] command description Result >> A = polyder(f1) Find the derivative of f1 A = 3 -2 3 >> B = polyder(f1,f2) Find the derivative of f1*f2 B = 15 12 -21 68 -18 >> [NUM DEN] = polyder(f1,f2) Find the derivative of NUM = 3 12 -45 8 -42 DEN = 9 36 -24 -120 100

Polynomial curve fitting (regression): polyfit MATLAB has the capability of fitting a function to a set of data points using polyfit. By this, you can find the best function representation for these points. The function could be linear, quadratic, cubic, exponential, logarithmic, power, …etc. As a general rule, if you have a set of n points, you will need a polynomial of order n-1 to pass through all these points. points Description Result x = [1 5] y = [4 -2] Linear polynomial is guaranteed to pass through all points x = [2 -3 0] y = [20 -12 7] Quadratic polynomial is guaranteed to pass through all points x = [11 15 20 4] y = [-9 0 13 30] Cubic polynomial is guaranteed to pass through all points x = [x1 x2 …… xn] y = [y1 y2 …… yn] n-1 polynomial is guaranteed to pass through all points

Polynomial curve fitting (regression): polyfit It is not necessarily always that we need a function that passes through all the points, especially when working with practical problems that generate approximate results that follow some pattern. Say we are studying the relation between the velocity and the stopping distance of a vehicle. The following relation will apply Kinetic – Friction = 0, or 0.5*m*V^2 – μ*m*g*d = 0, so d = 0.5*V^2/(μ*g). We know from physics that the relation is quadratic, but due to uncertainties not all the points will lie on the quadratic polynomial. The method used in this curve fitting is the least square method, which searches for the minimum summation of residuals between the f(xi) and yi. Syntax: p = polyfit(x,y,n) Where x is a vector with the horizontal coordinate of the data points. y is the dependent vector that has the vertical coordinates, and n is the order of the polynomial. p will be a vector that holds the fitted polynomial’s coefficients.

Polynomial curve fitting (regression): polyfit It is easy to fit any polynomial function, but sometimes we need to fit power, exponential, logarithmic,..etc. How to do it? The best option is to write it in the form y = m*x+b. Examples: Function Representation Description p1 = polyfit(log(x),log(y),1) p2 = polyfit(x,log(y),1) p3 = polyfit(log(x),y,1) p4 = polyfit(x,y.^-1,1)

Polynomial curve fitting and interpolation: interp1 Sometimes we need to study a point of interest that is not represented in the given points, but we have some information about the points before and after it. Interpolation is useful in studying intermediate points, use interpl. Syntax: yi = interp1(x,y,xi,'method') % xi is a vector of points to be interpolated % yi is the vector of interpolated values Define x = [1 2 3 4]; y = [1 3 6 8]; xi = [1.2 3.5] Method Representation Output 'linear' y1 = interp1(x,y,xi,'linear') y1 = 1.40 7.00 'spline' y2 = interp1(x,y,xi,'spline') y2 = 1.22 7.25 'cubic' y3 = interp1(x,y,xi,'cubic') y3 = 1.32 7.11

Plots curve fitting MATLAB has the property of fitting plotted curves as well. You need to plot your results first, and choose from Tools, Basic Fitting. x = [0:0.5:4]; y = [2 4 5 5.5 6 6.5 6.8 7 7.1];