Unit II Graphing Functions and Data

Similar documents
Activity: page 1/10 Introduction to Excel. Getting Started

Excel R Tips. is used for multiplication. + is used for addition. is used for subtraction. / is used for division

Getting Started With Mathematica

Section 7.6 Graphs of the Sine and Cosine Functions

Ph3 Mathematica Homework: Week 1

EXCEL 98 TUTORIAL Chemistry C2407 fall 1998 Andy Eng, Columbia University 1998

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:

Chapter 7: Analytic Trigonometry

Partial Derivatives (Online)

Getting Started With Mathematica

6.001 Notes: Section 6.1

Using Microsoft Excel

GETTING STARTED WITH MATHEMATICA

Table of Laplace Transforms

Lab1: Use of Word and Excel

Introduction to the workbook and spreadsheet

Basic stuff -- assignments, arithmetic and functions

DOWNLOAD PDF MICROSOFT EXCEL ALL FORMULAS LIST WITH EXAMPLES

Mathematical Experiments with Mathematica

Excel Basics Fall 2016

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

A Brief Introduction to Mathematica

Three-Dimensional (Surface) Plots

addition + =5+C2 adds 5 to the value in cell C2 multiplication * =F6*0.12 multiplies the value in cell F6 by 0.12

John's Tutorial on Everyday Mathcad (Version 9/2/09) Mathcad is not the specialist's ultimate mathematical simulator

ARRAY VARIABLES (ROW VECTORS)

Chapter 3: The IF Function and Table Lookup

EGR 111 Introduction to MATLAB

Physics 251 Laboratory Introduction to Spreadsheets

Contents 10. Graphs of Trigonometric Functions

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s.

Shorthand for values: variables

Pre-Lab Excel Problem

Unit 3 Fill Series, Functions, Sorting

Unit 3 Functions Review, Fill Series, Sorting, Merge & Center

EXCEL SPREADSHEET TUTORIAL

QUICK EXCEL TUTORIAL. The Very Basics

GENERAL MATH FOR PASSING

Excel For Algebra. Conversion Notes: Excel 2007 vs Excel 2003

Math 340 Fall 2014, Victor Matveev. Binary system, round-off errors, loss of significance, and double precision accuracy.

Excel for Gen Chem General Chemistry Laboratory September 15, 2014

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.

Mathematica Assignment 1

Formulas in Microsoft Excel

1 Introduction to Using Excel Spreadsheets

It can be confusing when you type something like the expressions below and get an error message. a range variable definition a vector of sine values

Formulas, LookUp Tables and PivotTables Prepared for Aero Controlex

Excel Basics: Working with Spreadsheets

2 A little on Spreadsheets

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

A Mathematica Primer

A Mathematica Tutorial

2 Second Derivatives. As we have seen, a function f (x, y) of two variables has four different partial derivatives: f xx. f yx. f x y.

MITOCW ocw f99-lec07_300k

Lab#1: INTRODUCTION TO DERIVE

How to Make Graphs with Excel 2007

Experiment 1 CH Fall 2004 INTRODUCTION TO SPREADSHEETS

Intro To Excel Spreadsheet for use in Introductory Sciences

Rio Hondo Prep Computer Applications Class

How to use Excel Spreadsheets for Graphing

Microsoft Excel Microsoft Excel

Handout: Handy Computer Tools

MTH 122 Calculus II Essex County College Division of Mathematics and Physics 1 Lecture Notes #11 Sakai Web Project Material

Increasing/Decreasing Behavior

Name: Dr. Fritz Wilhelm Lab 1, Presentation of lab reports Page # 1 of 7 5/17/2012 Physics 120 Section: ####

Introduction to Microsoft Excel

Preparation for Precalculus

The Excel Project: Excel for Accountants, Business People... from the Beginning Duncan Williamson

Fourier Transforms and Signal Analysis

Section 1.5 Transformation of Functions

1.2 Adding Integers. Contents: Numbers on the Number Lines Adding Signed Numbers on the Number Line

Instructions on Adding Zeros to the Comtrade Data

Dr Richard Greenaway

An Introduction to Maple This lab is adapted from a lab created by Bob Milnikel.

Introduction to Spreadsheets

Section 1.5 Transformation of Functions

INTRODUCTION TO DERIVE - by M. Yahdi

Math Modeling in Java: An S-I Compartment Model

The MathType Window. The picture below shows MathType with all parts of its toolbar visible: Small bar. Tabs. Ruler. Selection.

HANDS-ON START TO WOLFRAM MATHEMATICA. and Programming with the Wolfram Language. Cliff Hastings Kelvin Mischo Michael Morrison.

Applied Calculus. Lab 1: An Introduction to R

Handout: Handy Computer Tools

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

Intro. Speed V Growth

Using Excel for Graphical Analysis of Data

Intermediate Algebra. Gregg Waterman Oregon Institute of Technology

Parametric Curves, Polar Plots and 2D Graphics

Algebra 2 Common Core Summer Skills Packet

y= sin( x) y= cos( x)

Microsoft Excel 2010 Handout

(Ca...

MAT 003 Brian Killough s Instructor Notes Saint Leo University

Agenda. Spreadsheet Applications. Spreadsheet Terminology A workbook consists of multiple worksheets. By default, a workbook has 3 worksheets.

APPM 2460 PLOTTING IN MATLAB

Meeting 1 Introduction to Functions. Part 1 Graphing Points on a Plane (REVIEW) Part 2 What is a function?

DOING MORE WITH EXCEL: MICROSOFT OFFICE 2013

Skill Set 3. Formulas

Performing Basic Calculations

SHOW ME THE NUMBERS: DESIGNING YOUR OWN DATA VISUALIZATIONS PEPFAR Applied Learning Summit September 2017 A. Chafetz

Using Microsoft Excel

Transcription:

Unit II Graphing Functions and Data These Materials were developed for use at and neither nor the author, Mark Schneider, assume any responsibility for their suitability or completeness for use elsewhere nor liability for any damages or injury that may result from their use elsewhere. Unit II Page i

Unit II Graphing Functions and Data This activity guide gives you a quick but practical introduction to graphing functions and data using Excel and Mathematica. There is a great deal of overlap in the capabilities of each program, and each has its own drawbacks. In the broadest strokes, Mathematica is particularly conducive to working with analytic functions, and Excel more so with individual numbers (such as a set of measurements with associated error). However, any computer graphing ultimately relies on individual points at which the function of interest is evaluated. Because Excel lets you see the data as individual numbers in cells, we will use that to allow you to see what is happening on this microscopic level. This will then allow us to better understand what is happening when Mathematica gets confused. Guidebook Entry II.1: Damped Harmonic Oscillator Recall that a damped harmonic oscillator has two basic features to the motion as a function of time. First, it oscillates. This implies there is some sinusoidal function. Second, it dies away. This implies that there is a decreasing exponential. Sketch below what a position versus time graph for a damped oscillator looks like. Typically such a function is given by an expression like x(t) = e kt sin(ωt). Now let's see what that looks like by graphing it in Excel. To do this, first devote a couple of cells in some quiet space of your spreadsheet (say the top row) to hold values of k and ω. Then fill in a column of say one or two hundred values of t, starting 0 in increments of 0.05. In the next row, calculate x(t) as above. You will have to make references to the cells containing k and ω. You clearly want to be able to fill down, but this will cause a problem, unless you have already made this mistake before. Try to figure out what happened, but don't hesitate to ask your instructor if you are puzzled. Unit II Page 1

Now make a graph of the function with k and ω equal to 1. Does it look like what you sketched on the previous page? Sketch it below. What happens as you increase k? You can do this in your sheet, and the graph changes automatically. Describe what you observe. What happens as you increase ω? Describe what you observe. Now let's try the same exercise in Mathematica. You may want to quit Excel and save that sheet to make more room. Double click on Mathematica (not the Kernel). Mathematica comes in two parts. One is called the front end, which contains all the niceties that makes the graph come out and does the input and output. It has all the frills, and does very little of the calculating. The other is called the Kernel, and it is this that does all of the number crunching. This allows one to have the Kernel on one fast machine, and the front end on several slower machines. However, all of our machines are pretty equal in speed, so we don't make any use of this feature. However, it helps explain a peculiar feature of Mathematica. When you start it up, the Kernel sits idle until it is needed. Then, once you ask Mathematica to do something, the Kernel is loaded from the hard disk. So the first calculation you do seems to take forever; after that it is much more responsive. Try this out. Once Mathematica has started, type 2+2 followed by the Enter (NOT RETURN--Mathematica is very fussy) key. Wait half an eternity, and before you are too gray, you will know the Unit II Page 2

answer. Now, try exactly the same calculation a second time, and you should see a much faster response. What you have just done is used Mathematica as a calculator, but you should know it is a bit different than your average calculator. Try adding two numbers, and subtracting two numbers. Try multiplying two numbers. Then try dividing that old approximation for pi of 22/7. What happened? Mathematica is designed to do everything as accurately as possible. The most accurate thing to do with 22/7 is to retain it as a fraction, so that is what it does. But what if you want a decimal representation? Of course, Mathematica can do that. The simplest way is to follow any expression with //N. Try entering 22/7//N and describe what happens. But, you might say, I need to know this to greater precision. Simple; use the N expression in the following more cumbersome but more precise way: N[22/7,20] which gives you 20 digits of accuracy. This N also works on some of the constants that Mathematica keeps, or knows how to calculate, such as pi. For amusement, calculate pi to 1000 places, and write the last four of those below, so I know you did it. You may have already found that Mathematica is very fussy about punctuation. Not only does it always want the enter key and not the return, it also expects all of the functions and constants it knows about to be started with a capital letter, and all the ones you define to be started with a lower case letter. Fortunately, the program usually complains when it thinks you messed up. It also expects square brackets [ ] to enclose the arguments of functions. Curly braces { } are used to hold extra parameters that tell Mathematica how to present data (like limits of graphing, as you will see soon). Regular parentheses are used in telling Mathematica the order of execution in an expression; 5*(2+3) says add first, then multiply. Unit II Page 3

So, finally you are ready to make a graph. To make a simple graph of the damped oscillator, enter the following Plot[Exp[-t]*Sin[t],{t,0,10}] where the parameters in braces tell Mathematica to plot this as a function of t with the range of 0 to 10. Be careful of capitals, braces, commas, etc. Sketch what you get below. With Excel, we built in an easy way to modify k and ω. There is an easy way here too. Position the curser just before t in the Sin expression, and then type a value, say 3. Follow this with the enter key, and the graph will be redone. Play around a bit entering different values for k and ω. Now let us see some of the limits of these graphing programs. We will simply look at the function sin(ωt). Guidebook Entry II.2: Graphing trig functions: what went wrong? Quit Mathematica and go back to Excel. Create a sheet that evaluates sin(ωt) for at least 100 t values which start at zero, and step by 0.05. As we did before, make a convenient space to store ω. Start out with ω equal to 1, and make a graph of the function. You will probably find it easier to see if you add lines between points if they don't appear automatically. Increase ω to 2, 3, 5, and describe what happens to your graph. Unit II Page 4

Look at adjacent values of the sin function in your sheet. What happens to the difference between these neighboring values as you increase ω? Now, increase ω more significantly. Describe what happens as you make ω equal to 10, 20, 40. Now try 60, 90, 120. Any surprises? If so, can you explain what is happening? If you can't, or see no surprises, talk to your instructor. Can you find particularly perverse values of ω that make the graph unusual. Describe what you see for what values of ω.. Unit II Page 5

As we descussed earlier, all computer graphics is done by plotting a set of discrete points. If the spacing between points corresponds to a periodicity of the function, the peculiar effect you saw above occurs; it is called aliasing. Those of you who have taken the waves course have probably already done battle with this in a slightly different way, but it is the same effect. Mathematica tries to be smart about this by looking at the rate of change of the function, but it is not too difficult to get Mathematica confused as well. To see this, quit Excel and start Mathematica again. Use the Plot function to plot Sin[ωt], with a range specified from 0 to 10, where ω has values around 30, or around 60. Describe what you see. Is this the same effects you saw in Excel? How are they the same? How different? In mechanics, we often look at systems, especially oscillating systems, in a view called phase space. Phase space is a graphing region in which we plot velocity not as a function of time, but rather as a function of position. I use the term function loosely, because phase space plots are generally multiply valued. To make this plot, we need to first know how to get a velocity from our position function. The following exercise works through the details of that. Guidebook Entry II.3: Phase Space Plots If we want to graph velocity versus position, we first must calculate the velocity. The first way we will do this is using calculus. We know that the position as a function of time is given by x(t) = e kt sin(ωt). Demonstrate your calculus skills by differentiating this to get the velocity as a function of time. Unit II Page 6

Take your old spreadsheet, and add a column next to the position column that contains the analytical value for the velocity. One can also calculate the velocity numerically. That is, one can calculate a change in distance over a change in time for a small interval. So, if you have time in column A, position in column B, you can calculate a velocity for cell D3 as (B4-B3)/(A4-A3). Do this, and fill the entire column. What happens in the last cell? Now graph the analytical and the numerical velocities on the same graph. You may need to add lines and get rid of the markers to see them clearly. Are they nearly the same? Exactly the same? Can you explain any differences? You may want to discuss this with the instructor. Unit II Page 7

Now let's take the plunge, and graph v vs x (using either velocity column). Describe what you see. Make sure to include lines. What happens as you change ω? What happens as you change k? In particular, what happens if k=0? Now let's see how to do this in Mathematica. The way to make this kind of plot is to use the ParametricPlot function. The format of this is as follows: ParametricPlot[{x,v},{t,tmin,tmax}] where x and v are the full analytic expressions for the position and velocity as a function of time. Make this graph, and see what happens as you vary k and ω. Unit II Page 8

One last skill we should develop is the ability to make graphs that are functions of two dimensional space. This is an extremely important ability, since we have the habit of doing physics in two and three dimensions, and so we often have to represent functions of those spaces, for electric and magnetic fields, for quantum mechanical wave functions, or for fluid flow to name a few instances. Guidebook Entry II.4: Graphs in Three Dimensions For simplicity, we will use a simple function that will give us a nice surface as a function of x and y z(x, y) = sin(x y), even though this is not a very common function encountered in physical systems. First, let's use Excel. Make a column of y values in the A column, starting at A2, running from -2 to 2 in steps of 0.25. Then make a row of x values, starting at B1, running from -2 to 2 in steps of 0.25. Now, enter the formula for z(x,y) in cell B2. Make sure to make references to the x values all have the same row number by putting a $ in front of the number, and all y references have the same column letter by putting a $ in front of the letter. Fill this function both down and across. Select the resulting region, and make a new chart. If you use the chart wizard, select a 3D chart; if you don't use the chart wizard, change the resulting to a 3D chart using the buttons on the bottom, or the menu item. Describe/sketch your result. Click around on the graph, and see what you can change, and describe that. Unit II Page 9

Mathematica is quite adept at such graphs. Try the following command: Plot3D[Sin[x*y],{x,-2,2},{y,-2,2}] which should give you a very similar graph. Describe what you find. Which program do you prefer? Unit II Page 10

Homework Due 1/30/96 1. How does an error propagate through the log function? Take for an example y = ln(x). If x has an average value of 6 and a standard deviation of.2, what is the standard deviation of y? Do this by the calculus method, and then check your result with a spreadsheet. 2. Do the same sort of task for y=sin(x), when x has an average value of π/2 and a standard deviation of 1.0. Does the calculus method agree with the spreadsheet method? Explain any mysteries here! Which method do you believe more? 3. How does an error propagate through a power function, y = x n? Again, use both calculus and a spreadsheet (with n = 3 for the spreadsheet case). 4. Find the general rules, the equivalents of 2 f x = f x + y, y for sum and difference combinations. That is, find error propagation formulas for and y = x + y y = x - y. 2 Unit II Page 11