Curve Fitting, Loglog Plots, and Semilog Plots 1



Similar documents
PLOTTING DATA AND INTERPRETING GRAPHS

Part 1: Background - Graphing

What does the number m in y = mx + b measure? To find out, suppose (x 1, y 1 ) and (x 2, y 2 ) are two points on the graph of y = mx + b.

3.2 LOGARITHMIC FUNCTIONS AND THEIR GRAPHS. Copyright Cengage Learning. All rights reserved.

MATLAB Workshop 14 - Plotting Data in MATLAB

Graphing Linear Equations

Activity 6 Graphing Linear Equations

Absorbance Spectrophotometry: Analysis of FD&C Red Food Dye #40 Calibration Curve Procedure

Equations. #1-10 Solve for the variable. Inequalities. 1. Solve the inequality: Solve the inequality: 4 0

Review of Fundamental Mathematics

Because the slope is, a slope of 5 would mean that for every 1cm increase in diameter, the circumference would increase by 5cm.

Updates to Graphing with Excel

Slope-Intercept Equation. Example

Plot the following two points on a graph and draw the line that passes through those two points. Find the rise, run and slope of that line.

1.3 LINEAR EQUATIONS IN TWO VARIABLES. Copyright Cengage Learning. All rights reserved.

Elements of a graph. Click on the links below to jump directly to the relevant section

u = [ 2 4 5] has one row with three components (a 3 v = [2 4 5] has three rows separated by semicolons (a 3 w = 2:5 generates the row vector w = [ 2 3

CHAPTER 1 Linear Equations

Linear Equations. Find the domain and the range of the following set. {(4,5), (7,8), (-1,3), (3,3), (2,-3)}

Also, compositions of an exponential function with another function are also referred to as exponential. An example would be f(x) = x.

-2- Reason: This is harder. I'll give an argument in an Addendum to this handout.

Week 1: Functions and Equations

AP Physics 1 and 2 Lab Investigations

Questions: Does it always take the same amount of force to lift a load? Where should you press to lift a load with the least amount of force?

A Determination of g, the Acceleration Due to Gravity, from Newton's Laws of Motion

EXPERIMENT 3 Analysis of a freely falling body Dependence of speed and position on time Objectives

Determine If An Equation Represents a Function

High School Algebra Reasoning with Equations and Inequalities Solve systems of equations.

Beginner s Matlab Tutorial

Basic Understandings

Lecture 2 Mathcad Basics

Lecture 8 : Coordinate Geometry. The coordinate plane The points on a line can be referenced if we choose an origin and a unit of 20

Lesson 4: Solving and Graphing Linear Equations

Graphing Linear Equations in Two Variables

EdExcel Decision Mathematics 1

What are the place values to the left of the decimal point and their associated powers of ten?

x 2 + y 2 = 1 y 1 = x 2 + 2x y = x 2 + 2x + 1

Temperature Scales. The metric system that we are now using includes a unit that is specific for the representation of measured temperatures.

SEQUENCES ARITHMETIC SEQUENCES. Examples

F.IF.7b: Graph Root, Piecewise, Step, & Absolute Value Functions

Graphing Motion. Every Picture Tells A Story

Years after US Student to Teacher Ratio

Unit 9 Describing Relationships in Scatter Plots and Line Graphs

FREE FALL. Introduction. Reference Young and Freedman, University Physics, 12 th Edition: Chapter 2, section 2.5

Plots, Curve-Fitting, and Data Modeling in Microsoft Excel

Objectives. Materials

This activity will show you how to draw graphs of algebraic functions in Excel.

Lab E1: Introduction to Circuits

Vector Notation: AB represents the vector from point A to point B on a graph. The vector can be computed by B A.

Straightening Data in a Scatterplot Selecting a Good Re-Expression Model

Graphing Quadratic Functions

1 of 7 9/5/2009 6:12 PM

Valor Christian High School Mrs. Bogar Biology Graphing Fun with a Paper Towel Lab

Euler s Method and Functions

4.4 Transforming Circles

Section 1.1 Linear Equations: Slope and Equations of Lines

MATLAB Functions. function [Out_1,Out_2,,Out_N] = function_name(in_1,in_2,,in_m)

Linear functions Increasing Linear Functions. Decreasing Linear Functions

F B = ilbsin(f), L x B because we take current i to be a positive quantity. The force FB. L and. B as shown in the Figure below.

Scientific Graphing in Excel 2010

Overview. Observations. Activities. Chapter 3: Linear Functions Linear Functions: Slope-Intercept Form

MatLab Basics. Now, press return to see what Matlab has stored as your variable x. You should see:

AMATH 352 Lecture 3 MATLAB Tutorial Starting MATLAB Entering Variables

CHAPTER FIVE. Solutions for Section 5.1. Skill Refresher. Exercises

1 One Dimensional Horizontal Motion Position vs. time Velocity vs. time

Motion Graphs. Plotting distance against time can tell you a lot about motion. Let's look at the axes:

Using Excel (Microsoft Office 2007 Version) for Graphical Analysis of Data

1.2 GRAPHS OF EQUATIONS. Copyright Cengage Learning. All rights reserved.

Solving Equations Involving Parallel and Perpendicular Lines Examples

Scatter Plot, Correlation, and Regression on the TI-83/84

Transforming Bivariate Data

LINEAR EQUATIONS IN TWO VARIABLES

MATH 60 NOTEBOOK CERTIFICATIONS

8.7 Exponential Growth and Decay

Summary of important mathematical operations and formulas (from first tutorial):

Write the Equation of the Line Review

The Central Idea CHAPTER 1 CHAPTER OVERVIEW CHAPTER REVIEW

MATH Fundamental Mathematics IV

GENERAL SCIENCE LABORATORY 1110L Lab Experiment 6: Ohm s Law

Title ID Number Sequence and Duration Age Level Essential Question Learning Objectives. Lead In

Session 7 Bivariate Data and Analysis

Subject: Math Grade Level: 5 Topic: The Metric System Time Allotment: 45 minutes Teaching Date: Day 1

2.5 Transformations of Functions

How To Draw A Circle Of Radius 1 On A Computer (For A Computer)

Final Graphing Practice #1

Lines, Lines, Lines!!! Slope-Intercept Form ~ Lesson Plan

Lab: Graphing Activities TOTTEN

a. all of the above b. none of the above c. B, C, D, and F d. C, D, F e. C only f. C and F

Microeconomic Theory: Basic Math Concepts

Are Those Sunspots Really on the Sun?

The Point-Slope Form

Linear Approximations ACADEMIC RESOURCE CENTER

List the elements of the given set that are natural numbers, integers, rational numbers, and irrational numbers. (Enter your answers as commaseparated

containing Kendall correlations; and the OUTH = option will create a data set containing Hoeffding statistics.

ANALYSIS OF TREND CHAPTER 5

6.4 Normal Distribution

EXPERIMENT 11 UV/VIS Spectroscopy and Spectrophotometry: Spectrophotometric Analysis of Potassium Permanganate Solutions.

LAB 6: GRAVITATIONAL AND PASSIVE FORCES

Algebraic expressions are a combination of numbers and variables. Here are examples of some basic algebraic expressions.

Numerical integration of a function known only through data points

Transcription:

Curve Fitting, Loglog Plots, and Semilog Plots 1 In this MATLAB exercise, you will learn how to plot data and how to fit lines to your data. Suppose you are measuring the height h of a seedling as it grows. The height (measured in centimeters) will be a function of time t (measured in days). Suppose you measure the height once a day and you obtain the following data: t (days) 1 2 3 4 5 h (cm) 5.2 6.6 7.3 8.6 10.7 Let us plot these data in MATLAB. For this, you have to represent your data as one-dimensional arrays, which are also called vectors. You can define vectors in MATLAB as follows: >> t = [1 2 3 4 5] >> h = [5.2 6.6 7.3 8.6 10.7] Don t forget the spaces that separate the numbers in your vectors. Once you have entered your data, you can use the plot command to display your data: >> plot(t, h, ro ) The ro part of the plot command tells MATLAB to display your data points as red circles. This part of the plot command is optional. If you omit it, MATLAB will join your data points by straight lines. Try: >> plot(t, h) We really don t want lines joining each pair of consecutive data points in this exercise; and circles are a bit vague as markers for data points, so let us try this: >> plot(t, h, k+ ) Now the first and last data points have become invisible; let us make them reappear by changing the axes on our plot. You can force MATLAB to pick the interval [0, 6] for the x-axis and the interval [0, 15] for the y-axis by entering: >> axis([0 6 0 15]) Now look at the resulting graph. Does it appear that h(t) is a linear function? Certainly, there is no straight line that exactly fits all data points, but it appears that the growth of your seedling can be approximately described by a linear function. Which linear function would best fit your data points? This question is your first example of a curve fitting problem. In this case, we want to know which straight line best fits all the data points you have plotted in this graph. MATLAB has an easy command for finding this straight line. Enter: >> polyfit(t, h, 1) 1 Copyright c 2003 Winfried Just, Department of Mathematics, Ohio University. All rights reserved.

MATH266A Curve Fitting, Loglog Plots, and Semilog Plots 2 MATLAB returns two numbers. The first of these numbers, 1.3, is the slope of your line. The second number, 3.78 is its y-intercept. Let us plot this line on the same graph as the data points. First we must make sure that MATLAB does not erase the previous graph when you add the line. For this, enter: Now we want to use the plot command to draw the line. We have seen that this command plots data points and may connect them by straight lines. So we need to define vectors of (lots of) data points that lie on this straight line. First we define an x-vector. >> x = [0:0.5:6] MATLAB gives you lots of numbers because this command defines a vector whose first entry is 0, the last entry is 6, and the other entries are obtained in increments of 0.5. If you define long vectors this way, you do not want to see all these numbers on the screen. You can instruct MATLAB to suppress the output of a command by putting a semicolon at the end. Now let us define a y-vector that contains the function values of the x-vector for the function y(x) = 1.3x + 3.78: >> y = 1.3*x + 3.78 Although the definition of y looks like the definition of a number, y is really an array of numbers, since x is. Now let us plot the graph of the straight line that supposedly best fits our data points. This time we do want the plot command to connect points by straight lines! >> plot(x, y) Look at your graph. The straight line we found does seem to approximate our data points rather well, doesn t it? Before you print your graph,you want to properly label your axes and add a title to it. You can label the horizontal axis as follows: >> xlabel( time in days ) And the vertical axis: >> ylabel( seedling height in cm ) When labelling a graph, you always should indicate the units of your variables. Now you can add your name as a title to the graph, like: >> title( My name ) If this MATLAB exercise is being counted in your grade, then print this figure for submission. Next I want to show you how to use semilog and loglog plots to fit curves to data that appear to be governed by an exponential or power relationship. Since we will produce a fresh plot, let us enter: >> hold off Now suppose that you recorded, once every week, the length L (in centimeters) of a growing rodent pup and that you also recorded its mass m (in grams). You got the following measurements:

MATH266A Curve Fitting, Loglog Plots, and Semilog Plots 3 Let us define new vectors: >> L = [1.0 1.6 3.0 6.2 12.8] >> m = [0.1 0.3 2.1 19.0 168.7] Let us try to plot L as a function of t: >> plot(t, L, ro ) t (weeks) 1 2 3 4 5 L (cm) 1.0 1.6 3.0 6.2 12.8 m (g) 0.1 0.3 2.1 19.0 168.7 The data points, shown as red circles, do not appear to sit approximately on a straight line. How can we approximate them? To get an idea, we can try to display the same data points in a semilog plot. Enter: >> semilogy(t, L, ro ) Now the data points do appear to sit on a straight line! Note that while the scale on the horizontal axis (corresponding to the variable t) is still linear, the vertical axis (which depicts L) is now drawn on a logarithmic scale. We still can use our polyfit function to find an equation for this line, but now we need to remember that the line will depict a relationship between t and log 10 L. In MATLAB, log 10 L can be entered as log10(l). Thus we enter: >> polyfit(t, log10(l), 1) MATLAB tells us that a line of slope 0.2803 and y-intercept 0.3246 appears to fit the semilog plot best. In mathematical terms, this means that the data appear to approximately be related as follows: log 10 L = 0.2803t 0.3246 (1) Raising 10 to the power equal to both sides of equation (1) we obtain: or equivalently, 10 log 10 L = 10 0.2803t 0.3246 (2) L = 10 0.2803t 0.3246 (3) It follows that the length of the rodents appears to grow exponentially as a function of time. Let us check whether our predicted curve really fits the data. Enter: >> plot(t, L, ro ) To plot the graph of the exponential function, we define vectors x and y as before. This time you do want to suppress output by putting semicolons at the end. Note the little period in front of the exponentiation symbol in the definition of y. It must be there in order to indicate that we raise every

MATH266A Curve Fitting, Loglog Plots, and Semilog Plots 4 element of the array y to the stated power, as opposed to raising the whole array to a power, which is a different operation that is of no interest here. >> x = [1:0.01:5]; >> y = [10.ˆ(0.2803*x - 0.3246)]; Now enter: >> plot(x,y) and look at the figure. The exponential function does not fit the data perfectly, but reasonably well; doesn t it? Now add labels to the axes and your name as a title to the figure, and print it if submission is required. Finally, let us explore the relationship between the length L of your animal and its mass m. Since we will produce a fresh plot, let us enter: >> hold off Let us try to plot m as a function of L: >> plot(l, m, ro ) The data points, shown as red circles, do not appear to sit approximately on a straight line. How can we approximate them? To get an idea, we can try a semilog plot again. Enter: >> semilogy(l, m, ro ) The points on this graph do not appear to sit on a straight line, do they? So let us try to display the same data points on a log-log plot for a change. In curve fitting, you often have to experiment with different approaches before you get a good fit. Enter: >> loglog(l, m, ro ) Now the data points do appear to sit on a straight line! Note that the scales on both axes are now logarithmic. We still can use our polyfit function to find an equation for this line, but now we need to remember that the line will depict a relationship between log 10 L and log 10 m. Thus we enter: >> polyfit(log10(l), log10(m), 1) MATLAB tells us that a line of slope 2.9537 and y-intercept 1.0636 appears to fit the log-log plot best. In mathematical terms, this means that the data appear to approximately be related as follows: log 10 m = 2.9537 log 10 L 1.0636 (4) Raising 10 to the power equal to both sides of equation (4) and using laws of exponents we obtain: 10 log 10 m = 10 2.9537 log 10 L 1.0636 = (10 log 10 L ) 2.9537 10 1.0636 (5) Since L log 10 L = L and 10 1.0636 = 0.0864, we obtained the following power relationship for m as a function of L:

MATH266A Curve Fitting, Loglog Plots, and Semilog Plots 5 m = 0.0864L 2.9537 (6) This makes sense, since the mass of an animal should be approximately proportional to the third power of its length. Let us check whether our predicted curve really fits the data. Enter: >> plot(l, m, ro ) To plot the graph of the exponential function, we define vectors x and y as before. Again, you do want to suppress output by putting semicolons at the end. The vector x should cover the whole horizontal axis of our plot, so it should range from 0 to 14. >> x = [0:0.01:14]; >> y = [0.0864*x.ˆ2.9537]; Now enter: >> plot(x,y) and look at the figure. The power function does not fit the data perfectly, but reasonably well; doesn t it? Now add labels to the axes of your graph and your name as a title to the figure, and print it if submission is required.