Plotting II: By the end of this class you should be able to: Create a properly formatted engineering graph Create graphs of a function Place multiple plots.

Slides:



Advertisements
Similar presentations
Lecture 5.
Advertisements

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,
Introduction to Engineering MATLAB – 11 Plotting - 4 Agenda Multiple curves Multiple plot.
Empirical Model Building I: Objectives: By the end of this class you should be able to: find the equation of the “best fit” line for a linear model explain.
Introduction to Graphing Using MATLAB. Line Graphs  Useful for graphing functions  Useful for displaying data trends over time  Useful for showing.
Matlab Graphics S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: 2D Graphics.
1 Chapter 4 Curve Plotting with MATLAB MATLAB provides some very powerful features for plotting and labeling curves. These operations can be performed.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
STROUD Worked examples and exercises are in the text PROGRAMME F4 GRAPHS.
LIAL HORNSBY SCHNEIDER
§ 8.3 Quadratic Functions and Their Graphs.
§ 8.3 Quadratic Functions and Their Graphs. Graphing Quadratic Functions Blitzer, Intermediate Algebra, 5e – Slide #2 Section 8.3 The graph of any quadratic.
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
Statistical Analysis with Excel
Introduction Many relationships can be represented by linear equations. Linear equations in two variables can be written in the form y = mx + b, where.
By Hrishikesh Gadre Session II Department of Mechanical Engineering Louisiana State University Engineering Equation Solver Tutorials.
EGR106 Week 6 MATLAB FILES Two Dimensional Plots Multiple Plots
EGR106 Week 4 Two Dimensional Plots Multiple Plots Plot Formatting Homework.
Dr. Jie Zou PHY Welcome to PHY 3320 Computational Methods in Physics and Engineering.
An introduction to Plotting in MATLAB Rikard Johansson Department of Biomedical Engineering (IMT) Linköping University
EPSII 59:006 Spring Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops.
Maybe we should look at some diagrams.
3 Polynomial and Rational Functions © 2008 Pearson Addison-Wesley. All rights reserved Sections 3.1–3.4.
Mathcad Variable Names A string of characters (including numbers and some “special” characters (e.g. #, %, _, and a few more) Cannot start with a number.
MOTION.
Quadratic Functions and Their Graphs
For loop Khairul anwar.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
ENG College of Engineering Engineering Education Innovation Center 1 2D Plots 1 in MATLAB Topics Covered: 1.Plotting basic 2-D plots The plot()
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Unit 7: Non-Linear Equations & Real- World Applications Section 1: Compound Interest Using 5x³: 5 is the coefficient, x is the base, 3 is the exponent.
Ranjeet Department of Physics & Astrophysics University of Delhi Working with Origin.
Kinematics (1-d) Mr. Austin. Motion ______________is the classification and comparison of an objects motion. Three “rules” we will follow: – The motion.
Inquiry Unit.
Descriptive Statistics II: By the end of this class you should be able to: describe the meaning of and calculate the mean and standard deviation of a sample.
Descriptive Statistics I: By the end of this class you should be able to: Palm: Section 7.1, 7.2 Program cords and delays in your music programs plot a.
MATLAB Tutorial EE 327 Signals and Systems 1. What is MATLAB? MATLAB – Matrix Laboratory The premier number-crunching software Extremely useful for signal.
V. Rouillard  Introduction to measurement and statistical analysis GRAPHICAL PRESENTATION OF EXPERIMENTAL DATA It is nearly always the case that.
Physics. Good News/Bad News: These are the same formulas we used for linear motion. Do you know them? If the answer is “NO”, then get familiar with them.
Physics Honors. Good News/Bad News: These are the same formulas we used for linear motion. Do you know them? If the answer is “NO”, then memorize them.
Motion in One Direction Chapter : Displacement and Velocity Main Objectives:  Describe motion in terms of frame of reference, displacement, time,
Accelerated Motion Merrill Physics Principles and Problems.
Recap Sum and Product Functions Matrix Size Function Variance and Standard Deviation Random Numbers Complex Numbers.
1 DKT 211 Basic Communication Engineering LAB # 1A : (Lecture 1) Introduction to Matlab  Basic Features  Scientific features  Array Operations  Script.
Structured Programming I – Relational & Logical Operators Objectives: By the end of this class you should be able to: Change graph interactively in EXCEL.
MATLAB – PT1 The purpose of this workshop is to get you started and to have fun with MATLAB! Let’s talk a little and decide on what we will be covering.
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
Files: By the end of this class you should be able to: Prepare for EXAM 1. create an ASCII file describe the nature of an ASCII text Use and describe string.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
1-d Arrays & Plotting.
Polynomials, Curve Fitting and Interpolation. In this chapter will study Polynomials – functions of a special form that arise often in science and engineering.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
ENG College of Engineering Engineering Education Innovation Center 1 2D Plots 2 in MATLAB Topics Covered: 1.More about 2-D plots  Placing multiple.
Introduction to Engineering MATLAB – 9 Plotting - 2 Agenda Formatting plots.
Warm Up Find the x-intercept of each function. (plug in zero for y and simplify 1. f(x) = –3x f(x) = 6x + 4 Factor each expression. 3. 3x 2 – 12x4.
STROUD Worked examples and exercises are in the text 1 STROUD Worked examples and exercises are in the text Programme F4: Graphs PROGRAMME F4 GRAPHS.
MATLAB ® for Engineers, Holly Moore Fourth Edition, Global Edition © Pearson Education Limited 2015 All rights reserved. Figure 5.1 Simple Plot of Time.
Chapter Projectile Motion 6.1.
MOTION. Chapter Four: Motion  4.1 Position, Speed and Velocity  4.2 Graphs of Motion  4.3 Acceleration.
Non-Linear Functions and Real-World Applications.
Projectile Motion Problem
Structured Computer Programming EE 201 Introduction to MATLAB 7 for Engineers بسم الله الرحمن الرحيم King Abdulaziz University College of Engineering Dept.
MAE 421 Matlab review Prof. Mark Glauser Created by: David Marr.
How to use MATLAB (using M-files) Double click this icon To start Matlab 6.5.
Computer Application in Engineering Design
Lecture 25.
Chapter Projectile Motion 6.1.
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.
Microsoft Excel 101.
Projectile Motion Physics Honors.
Presentation transcript:

Plotting II: By the end of this class you should be able to: Create a properly formatted engineering graph Create graphs of a function Place multiple plots in one figure Plot a polynomial functions Find polynomial roots by graph and by command Change the tick marks and tick labels on a graph Text: §§

Review Exercise: Please complete in pairs Download the water vapor pressure data file from Data Files page This file contains two columns of data: Column 1 = Temperature (K) Column 2 = Vapor Pressure of Water (Torr) Prepare a Script that will: Load this file into MATLAB Plot Temp (x-axis) vs Vapor Pressure (y-axis) Label the axes Copy the script and the resulting graph into word and print out

Review: Plot commands Simple x/y plot >> plot(x,y)or >> plot(x,y,’*’) Plot multiple data >> plot(x1,y1,’+’,x2,y2,’p’) Labeling & Adjusting the graph >> xlabel(‘x-axis title’), ylabel(‘y-axis label’) >> legend(‘label 1’, ‘label 2’, …) >> gtext (‘text’) >> grid on/off >> axis([xlow, xhigh, ylow, yhigh])

Graphing Requirements ( pg 262) 1. axis label with quantity and units 2. regularly spaced, easy to interpret tick marks 3. label multiple curves 4. use title to distinguish as necessary 5. plot data using a symbol (6. avoid connection lines) 7. Plot functions using lines

Plan an x range to plot Create an x vector Calculate the y value for each x Plot x vs. y Revise x range and vector if necessary Review: General Procedure for plotting functions:

A projectile is thrown straight upward. It’s height is governed by the formula: where: h = height of the projectile v 0 = the initial velocity of the projectile = 50 m/s t = the elapsed time in seconds g = the acceleration of gravity = 9.8 m/s 2 How would you plot the height of the projectile vs. time?

Steps to plot projectile need to figure out how long it will be until the projectile hits the ground (so we know how long the x vector should be). –set height equal to zero –will equal zero if either term is zero, t=0 is one solution –for the other solve for time end now set up the x vector >> t = 0:1:tend; plug into function to get heights >> h = 50*t – 0.5*9.8*t.^2; now plot the result >> plot(t,h), xlabel(‘time (s)’), ylabel(‘height (m)’)

Steps to plot projectile (cont.) Resulting plot Plot is adequate but could be better. it does not actually reach the ground the curve is a little choppy. fix these problems with a new x vector >> t = linspace(0, tend, 40); or >> t = 0:0.025*tend:tend; calculate h and plot as before.

Write a function to plot height of projectile vs. time (complete a function development worksheet in the process) It’s height is governed by the formula : where: h = height of the projectile v 0 = the initial velocity of the projectile = 50 m/s t = the elapsed time in seconds g = the acceleration of gravity = 9.8 m/s 2 Also Remember:

1.Problem Statement: We wish to create a function that will plot the height vs. time of a projectile thrown straight up with an initial velocity of v 0. The graph should cover from initial launch through when the projectile returns to the ground. Inputs Variable NameDescriptionUnitsInput Source * v0the initial velocitym/sec.command line Outputs Variable NameDescriptionUnitsOutput type * NAA plot of height vs. timem, sec.display figure Handout summary sheet – have students work on function

4.Solution Steps/Test Calculation solution steps: calculate total time (tend): (tend = 2v0/g) create an x vector (x = linspace(0, tend, 50)) plug into formula to create a y vector (previous formula) plot with proper labels test calculation: we do need some key points to validate the result first we can check if the curve hits zero at 10.2 sec. next we can check the maximum height (when will that occur?) which comes at ½ the total time (5.2 sec) h max = (50 m/)(5.2 s) – 0.5*9.8 m/s 2 )(5.2 s) 2 = m;

5.Coding (continues in next frame): function projectile(v0) % This function calculates the height of a projectile versus % time when launched upward with an initial speed of v0. It % plots ten points on the graph of height vs time. % % function projectile(v0) % input variables: v0 = initial speed (m/sec) % output: a graph of height vs time. % other variables: % g = acceleration of gravity (m/sec2) % h = vector of heights of the projectile (m) % t = vector of times corresponding to above heights (m) % tend = time until projectile hits the ground again (s) % S. Scott Moor February 2006

% Calculate final time g=9.8; tend = 2*v0/g; % Set up the time vector t=0:0.02*tend:tend; % Calculate the corresponding heights h=v0*t - 0.5*g*t.^2; % Ploting the results plot(t,h) xlabel 'time (s)', ylabel 'height (m)' V = num2str(v0); b =['Projectile height, v_0 = ', V, 'm/sec']; title(b)

Validation: 6.Test case check: Run function with v0 = 50, does it match test calculation? 7.Reality Check: Now we need this step, we have only checked the curve at a couple of points. Look at the overall curve – Does it look like what you would expect (i.e., does it look like a parabola)? 8.Test on wider cases: Try the function several times with different inputs. Does it continue to give the graphs you would expect?

Graphing Hints ( pg 281, 282) Plan Axes Use sensible tick mark spacing Avoid trailing zeros Start Axes from zero whenever possible Use different line types for each curve (plots must be “xeroxible” ) Use same axis range and tick mark spacing for graphs that will be compared Avoid clutter (too many curves in one area)

Go to ENGR 121 page Download: –analyze.m and –piano.wav Run >> analyze(‘piano’)

Analyze.m [y, Fs] = wavread(file); % y is sound data, Fs is sample frequency. t = (1:length(y))/Fs; % time ind = find(t>0.1 & t<0.12); % set time duration for waveform plot figure; subplot(1,2,1) plot(t(ind),y(ind)) axis tight title(['Waveform of ' file]) N = 2^12; % number of points to analyze c = fft(y(1:N))/N; % compute fft of sound data p = 2*abs( c(2:N/2)); % compute power at each frequency f = (1:N/2-1)*Fs/N; % frequency corresponding to p subplot(1,2,2) semilogy(f,p) axis([ ^-4 1]) title(['Power Spectrum of ' file])

To notice in Analyze.m subplot command – creates multiple plots on one figure >> subplot( rows, columns, current location) figure command – creates a new figure window (instead of overwriting an existing plot) >> figure Shape of figure grid # indicating the space on the grid for the next plot

Complete the Exercises: “Plotting Polynomials and other graphing stuff” (see handout) 1.Plotting polynomials 2.Adjusting tick marks 3.Plotting Polynomials with Polyval 4.Finding roots graphically 5.Roots command 6.Using the “hold” command

Review: Zooming and holding plots Zooming in on a plot (>> poly1 % plot set up script): >> axis([ ])% adjust the axis Using data curser: –Select from tool bar, place near zero of curve –move right/left with curser keys, find point nearest zero –right click and choose “Create New Datatip” to point to other zeros Adding a line at zero >> hold on% holds existing plot >> x = [ ];% set x high & low limits >> y0 =[0, 0];% set y equal to zero >> plot(x,y0)% add to plot >> hold off% turn hold off Adjust plot axis interactively Choose: Edit  Axis Properties..., change values in dialogue