Lecture 10 2D plotting & curve fitting

Slides:



Advertisements
Similar presentations
1 Chapter 13 Curve Fitting and Correlation This chapter will be concerned primarily with two separate but closely interrelated processes: (1) the fitting.
Advertisements

Plotting Selim Aksoy Bilkent University Department of Computer Engineering
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.
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
CITS2401 Computer Analysis & Visualisation
Regression Regression: Mathematical method for determining the best equation that reproduces a data set Linear Regression: Regression method applied with.
Lecture 9 Plotting in 2-D Plotting in 2-D, Plotting Multiple Curves, Plotting with Figures, Plot Settings, Scaling, Legends © 2007 Daniel Valentine. All.
Chapter 5 Plotting Data Curve Fitting, Good Graphing Practices Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Plotting 1.Overview 2.plot in 2D 3.Plot in 3D 4.Other possible charts 5.Engineers: label your plots! 6.Plots & Polynomial.
Matlab intro The Environment
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.
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Graphing. The Important Elements of a Graph  Horizontal Axis (X-Axis)  The Independent Variable. A change in this variable affects the y variable. 
Introduction to MATLAB for Engineers, Third Edition Chapter 6 Model Building and Regression PowerPoint to accompany Copyright © The McGraw-Hill Companies,
MATLAB Plotting With MATLAB 1. Two Dimensional Plots The xy plot is the most commonly used plot by engineers The independent variable is usually called.
Recap Summary of Chapter 6 Interpolation Linear Interpolation.
MATLAB for Engineers, by Holly Moore. ISBN © 2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is.
Graphing.
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.
Scientific Computing General Least Squares. Polynomial Least Squares Polynomial Least Squares: We assume that the class of functions is the class of all.
11/20/2015ENGR 111A - Fall MatLab – Palm Chapter 5 Curve Fitting Class 14.1 Palm Chapter:
Recap Chapter 5 “Plotting” Two Dimensional Plots Simple x-y Plots Titles, Labels and Grids Multiple Plots.
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
Polynomials, Curve Fitting and Interpolation. In this chapter will study Polynomials – functions of a special form that arise often in science and engineering.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Chapter 15 General Least Squares and Non- Linear.
Data Analysis, Presentation, and Statistics
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
MATLAB ® for Engineers, Holly Moore Fourth Edition, Global Edition © Pearson Education Limited 2015 All rights reserved. Figure 5.1 Simple Plot of Time.
Chapters 8 Linear Regression. Correlation and Regression Correlation = linear relationship between two variables. Summarize relationship with line. Called.
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.
Plotting in Excel Ken youssefi Engineering 10.
Matlab Training Session 11: Nonlinear Curve Fitting
Introduction to Elementary Statistics
Introduction to Programming for Mechanical Engineers
Salinity Calibration fit with MATLAB
Plotting Chapter 5.
Lecture 25.
Transforming Graphs of Functions
Lecture 25: Exploring data
Section 1.1 The Distance and Midpoint Formulas; Graphing Utilities; Introduction to Graphing Equations.
IB Physics: Chapter 1 Lesson 2b: Graphs.
Two-Dimensional Plots
Relationships and Graphing
Understanding Standards Event Higher Statistics Award
Scatterplots A way of displaying numeric data
Making Science Graphs and Interpreting Data
Section 5: Graphs in Science
Investigating Relationships
Final Exam Review Part 2 - MATLAB
Correlation and Regression
Making Science Graphs and Interpreting Data
Graphs in Science Chapter 1, Section 5 Page 34.
MatLab – Palm Chapter 5 Curve Fitting
Lecture Notes The Relation between Two Variables Q Q
Bellringer Are sales up or down? How do you know?.
MatLab – 2D Plots 2 MATLAB has many built-in functions and commands to create various types of plots. Instructor notes: We start with an example of some.
^ y = a + bx Stats Chapter 5 - Least Squares Regression
LECTURE 2: MATH REVIEW.
Motion and Force. Motion and Force Chapter Twelve: Distance, Time, and Speed 12.1 Distance, Direction, and Position 12.2 Speed 12.3 Graphs of Motion.
Transforming Graphs of Functions
Least-Squares Regression
3.1 Reading Graphs; Linear Equations in Two Variables
Graphing.
Graphs in Science.
Graphing Linear Equations
Multivariate Analysis Regression
Data Management Learning Goals:
Making Science Graphs and Interpreting Data
Curve Fitting in Matlab
Presentation transcript:

Lecture 10 2D plotting & curve fitting Subplots Other 2-D Plots Curve fitting © 2010 Daniel Valentine. All rights reserved. Published by Elsevier.

Plotting and Curve Fitting Visualizing trends by plotting large sets of data from experiments or from computer calculations helps you interpret the data. There are numerous grapical tools available in MATLAB. Curve fitting is a powerful way to use a set of data to find a mathematical model that approximates the set of data.

Subplots Subplot command allows you to put multiple graphs on one figure window. subplot(m,n,p) divides figure window into a grid of m rows and n columns. Variable p identifies the part of the window where the plot is placed. p = 1 p = 2 p = 3 p = 4

Examples of subplots To graph sin(x) and cos(x) on the same figure side-by-side do the following: When a figure with a subplot is open, you must close it before opening a new figure in order for the new figure to display properly.

Other utilities for 2-D plots MATLAB supports several 2-D plotting utilities: Polar plots Logarithmic plots Bar graphs Pie charts

Polar plots MATLAB supports tools for plotting data in polar coordinates.

Logarithmic plots MATLAB has tools for three kinds of logarithmic plots: semilogx semilogy loglog These pltting utilities automatically replace linear scales with logarithmic scales. Logarithmic scales are useful when a variable ranges over many orders of magnitude.

Example: Logarithmic plots & subplots

Bar charts Bar graphs are useful for reporting data. x = [1,3,8,5,4,6]; bar(x); generates a vertical bar graph. barh(x); generates a horizontal bar graph.

Pie charts Pie charts are another useful way of reporting data. pie(x); 8/(1+3+8+5+4+6) ≈ 30% (cyan section) 5/(1+3+8+5+4+6) ≈ 19% (yellow section) etc.

Curve fitting The simplest way to fit a set of 2D data is a straight line. Linear regression is a method of fitting data with a straight line. Linear regression minimizes the squared distance between data points and the equation modeling the data points. This prevents positive and negative “errors” from canceling.

Linear approximation by hand slope ≈ (y2-y1)/(x2-x1) = (0-15) / (5-0) = -3 Crosses y axis at 15 (note the point (0,15) in our data) yhand = -3x + 15 sum_of_squares = sum((y - yhand).^2) = 5

polyfit function The polyfit function takes (x, y) data, and the degree n of a polynomial as input. It returns the coefficients of the polynomial of degree n that best fits the data. Using our data: So, yLR = -2.9143x + 14.2857 sum_of_squares2 = sum((yLR - y).^2) = 3.3714

Best Fit Comparison

Polynomial regression Polynomial regression is used to fit a set of data with a polynomial. The polyfit function can be used to find the best fit polynomial of a specified degree; the result is the coefficients. Warning: Increasing the degree of the best fit polynomial can create mathematical models that may fit the data better, but care must be taken in your interpretation of the result.

polyval function polyfit returns the coefficients of a polynomial that best fits the data. To evaluate the polynomial at any value of x, use the polyval function. polyval requires two inputs: the array of coefficients and the array of x-values at the locations the polynomial is to be evaluated.

Example using polyval Referring to the data from this lecture that we used from the polyfit example: Now try plotting fitted_data vs. x and yLR vs. x. Identical graphs are generated.

Exercises Use subplots to create normal and polar plots of y = cos(x) + sin(x) in the same figure window for –π ≤ x ≤ π. Use polyfit to find a 3rd degree polynomial to fit the following set of data: x = -5:1:4 y = [-506.6, -262.88, -99.43, -36.78, 6.2, 7.11, 16.6, 51, 183, 427.97]. Plot the best fit curve and the data points on the same figure.

Summary Example usage subplots Other 2-D plots: polar and logarithmic Bar charts and pie charts Curve fitting Linear regression concept polyfit function polyval function