Sept. 26, 2005 Lecture 6 - By Paul Lin 1 CPET 190 Lecture 6 Problem Solving with MATLAB

Slides:



Advertisements
Similar presentations
Introduction to Engineering MATLAB – 11 Plotting - 4 Agenda Multiple curves Multiple plot.
Advertisements

Plotting Selim Aksoy Bilkent University Department of Computer Engineering
Lecture (4) Plotting & Programming (1) Eng. Osama Talaat 1.
2D Plots 1 ENGR 1181 MATLAB 12.
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.
Matrix Manipulation and 2D Plotting
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
Introduction to Matlab EE 2303 Lab. MATLAB stands for “Matrix Laboratory” APPLICATIONS OF MATLAB:  Mathematical Calculations  Data Analysis & Visualization.
Al-Amer An Introduction to MATLAB Lesson 2: M-files Dr. Samir Al-Amer Term 061.
MATLAB’s extensive, device-independent plotting capabilities are one of its most powerful features. They make it very easy to plot any data at any time.
MATLAB GRAPHICS 2-D.
EGR106 Week 6 MATLAB FILES Two Dimensional Plots Multiple Plots
Vectors and Plotting Selim Aksoy Bilkent University Department of Computer Engineering
Introduction to MATLAB ES 156 Signals and Systems 2008 Harvard SEAS.
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
Introduction to MATLAB ES 156 Signals and Systems 2007 Harvard SEAS Prepared by Jiajun Gu.
Lecture 9 Plotting in 2-D Plotting in 2-D, Plotting Multiple Curves, Plotting with Figures, Plot Settings, Scaling, Legends © 2007 Daniel Valentine. All.
Plotting - Advanced. FPLOT Plots a function f(x) written as a string within quotation marks. The free variable needs to be designated with x. The lower.
Introduction to Matlab Jianguo Wang CSSCR September 2009.
An introduction to Plotting in MATLAB Rikard Johansson Department of Biomedical Engineering (IMT) Linköping University
Matlab intro The Environment
MATLAB Fundamentals.
Designing Effective Graphics Using MATLAB The Cain Project in Engineering and Professional Communication ENGINEERING SERIES.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
ENG College of Engineering Engineering Education Innovation Center 1 2D Plots 1 in MATLAB Topics Covered: 1.Plotting basic 2-D plots The plot()
„  1999 BG Mobasseri1 9/18/2015 June 2 GRAPHICS IN MATLAB- PART I BASIC PLOTTING.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
COMP 116: Introduction to Scientific Programming Lecture 5: Plotting, Scripts and publishing.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
MAE 1202: AEROSPACE PRACTICUM An Introduction to MATLAB: Part 2 Mechanical and Aerospace Engineering Department Florida Institute of Technology Developed.
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.
Lecture 2 - Matlab Introduction CVEN 302 June 5, 2002.
Designing Effective Graphics Using MATLAB The Cain Project in Engineering and Professional Communication Linda Driskill, Gang Cheng,
1 DKT 211 Basic Communication Engineering LAB # 1A : (Lecture 1) Introduction to Matlab  Basic Features  Scientific features  Array Operations  Script.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 4: Intro to Plotting Wednesday 10 Sept 2014 EGR 115 Introduction to Computing for Engineers.
Recap Chapter 5 “Plotting” Two Dimensional Plots Simple x-y Plots Titles, Labels and Grids Multiple Plots.
EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,
1. Overview 2. plot in 2D 3. Plot in 3D 4. Other possible charts 5. Engineers: label your plots! 6. Plots & Polynomial Plotting 11.
EGR 115 Introduction to Computing for Engineers 2D Plotting – Part I Wednesday 17 Sept 2014 EGR 115 Introduction to Computing for Engineers.
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.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Introduction to Engineering MATLAB – 9 Plotting - 2 Agenda Formatting plots.
MATLAB ® for Engineers, Holly Moore Fourth Edition, Global Edition © Pearson Education Limited 2015 All rights reserved. Figure 5.1 Simple Plot of Time.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Lab 2 : potting to Matlab Networks.
Plotting. 2 Initializing Vectors colon operator x = 1:2:10 x = y = 0:0.1:0.5 y =
Outline What is MATLAB MATLAB desktop Variables, Vectors and Matrices Matrix operations Array operations Built-in functions: Scalar, Vector, Matrix Data.
EGR 106 – Week 5 – 2-D Plots Question : Why do engineers use plots? Answer : To analyze, visualize, and present data. Matlab has many useful plotting options.
How to use MATLAB (using M-files) Double click this icon To start Matlab 6.5.
Plotting ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Creating a Plot The plot function can take one or more inputs; e.g. plot (x, y) or plot (y) Note that in the two-argument version, the vectors x and.
Introduction to MATLAB
Computer Application in Engineering Design
Lecture 25.
Ch3 Graphics Overview of Plotting Editing Plots
Lecture 25: Exploring data
Two-Dimensional Plots
MATLAB How to use (using M-files) Double click this icon
MATLAB How to use (using M-files) Double click this icon
Plotting Multiple Graphs In The Same Plot
MATLAB How to use (using M-files)
Plotting Signals in MATLAB
Designing Effective Graphics Using MATLAB
Presentation transcript:

Sept. 26, 2005 Lecture 6 - By Paul Lin 1 CPET 190 Lecture 6 Problem Solving with MATLAB

Sept. 26, 2005 Lecture 6 - By Paul Lin 2 Lecture 6: MATLAB Plotting 6-1 Introduction to Plotting 6-2 Simple X-Y Plots Printing a PlotPrinting a Plot Exporting a Plot as a Graphical ImageExporting a Plot as a Graphical Image Line Color, Style, Marker and LegendsLine Color, Style, Marker and Legends 6-3 Multiple Plot 6-4 Logarithmic Scales 6-5 Plotting Applications

Sept. 26, 2005 Lecture 6 - By Paul Lin Introduction to Plotting Data or Numerical facts Data or Numerical facts For making decision makingFor making decision making Pictures, Graphs, or Plots Pictures, Graphs, or Plots Describe dataDescribe data Ohms Laws: V = R * IOhms Laws: V = R * I MATLAB Plotting Capabilities MATLAB Plotting Capabilities 2-D XY Plot2-D XY Plot Semilog PlotSemilog Plot 3-D Plot3-D Plot MoreMore

Sept. 26, 2005 Lecture 6 - By Paul Lin Simple XY Plots Basic Steps for Preparing a XY Graph Basic Steps for Preparing a XY Graph 1.Prepare data for x-axis and y-axis in row vector or column vector format 2.Select a window with a figure number and plot position (if multiple sub-plot) 3.Call plot() function 4.Select plot line, color, etc 5.Set Axis range and grid 6.Annotate the plot 7.Export graph MATLAB XY Plot Related Functions MATLAB XY Plot Related Functions figure, plot, subplot, set, grid on, axis, xlabel, ylabel, title, legend, textfigure, plot, subplot, set, grid on, axis, xlabel, ylabel, title, legend, text

Sept. 26, 2005 Lecture 6 - By Paul Lin Simple XY Plots (cont.) Example 6.1 Plot the function y = x 2 – 10x + 15 (from page of MATLAB Programming for Engineers, 3 rd, by Stephen J. Chapman, published by Thomson-Learning) Solution Planning Planning 1.Prepare x vector, with reasonable range, and compute y vector 2.Use a default window ( without figure), and call plot(x,y) function 3.Add title(), xlabel(), ylabel(), grid on, etc to fine-tune the graph

Sept. 26, 2005 Lecture 6 - By Paul Lin Simple XY Plots (cont.) Example 6-1 (cont.) MATLAB Solution: Start MATLAB, and invoke M-File Editor Start MATLAB, and invoke M-File Editor Write the following MATLAB statements Write the following MATLAB statements %plotxy_p56.m x = 0:1:10; % NOT y = x^2 - 10*x + 15 y = x.^ *x + 15; plot(x, y); title('y = x.^ *x + 15'); xlabel('x axis'), ylabel('y axis'); grid on;

Sept. 26, 2005 Lecture 6 - By Paul Lin Simple XY Plots (cont.) Example 6-1 (cont.) Verifying Data:Verifying Data: X = 0, Y = 15 Y = 0 – = 15 Y = 0 – = 15 X = 10, Y = 15 Y = 10^2 - 10* = 15 Y = 10^2 - 10* = 15 Exporting FigureExporting Figure Copy Figure for ExportingCopy Figure for Exporting

Sept. 26, 2005 Lecture 6 - By Paul Lin Simple XY Plots (cont.) Example 6-1 (cont.) Exporting TIFF Figure to PowerPoint applications like this one 1. On MATLAB Command Windows: we type >> print –dtiff plotxy_56.tif %for creating graphic files 2. We locate the plotxy_56.tif in the current directory – OK. 3. We start and setup PowerPoint, then Insert -> Picture to locate plotxy_56.tif file.

Sept. 26, 2005 Lecture 6 - By Paul Lin Multiple Plots Multiple Plots Multiple Plots On the same Graph using plot function, orOn the same Graph using plot function, or Arranged in m x n matrix formatArranged in m x n matrix format subplot(2,1,1) – 2 subplots, two rows, one column, the first plot subplot(2,1,1) – 2 subplots, two rows, one column, the first plot subplot(2,2,1) – 4 subplots, two rows, two column, the first plot subplot(2,2,1) – 4 subplots, two rows, two column, the first plot >> help subplot>> help subplot Examples Examples >> subplot(2,1,1), plot(sine) >> subplot(2,1,2), plot(cosine)

Sept. 26, 2005 Lecture 6 - By Paul Lin Multiple Plots Example 6-2. Multiple plots of sine and cosine from the equation (from page of MATLAB Programming for Engineers, 3 rd, by Stephen J. Chapman, published by Thomson- Learning) Example 6-2. Multiple plots of sine and cosine from the equation (from page of MATLAB Programming for Engineers, 3 rd, by Stephen J. Chapman, published by Thomson- Learning) Analysis Analysis Data preparationData preparation X vector from 0 to 2pi X vector from 0 to 2pi Y1 = sin2x Y1 = sin2x Y2 = 2cos2x Y2 = 2cos2x Two plots subplot(2,1,1), and subplot(2,1,2)Two plots subplot(2,1,1), and subplot(2,1,2)

Sept. 26, 2005 Lecture 6 - By Paul Lin Multiple Plots Example 6-2 (cont.) MATLAB Program MATLAB Program %plot_sine_cosine.m x = 0:pi/100:2*pi; y1 = sin(2*x); y2 = 2*cos(2*x) figure(1), plot(x,y1, x, y2) figure(2),subplot(2,1,1),plot(x,y1), title('sin 2x'); figure(2),subplot(2,1,2),plot(x,y2), title('2cos 2x');

Sept. 26, 2005 Lecture 6 - By Paul Lin Multiple Plots Distinguish different plots Distinguish different plots Line ColorLine Color Line StyleLine Style Marker Style andMarker Style and LegendsLegends help plot for more info help plot for more info Example 6-3 Example 6-3%plot_p60.m x = 0: 1: 10; y = x.^ *x + 15; plot(x,y,'r--', x, y, 'bo');

Sept. 26, 2005 Lecture 6 - By Paul Lin Multiple Plots Legends Legends Name and its line styleName and its line style Example 6-4 Example 6-4 %plot_sine_cosine_legend.m x = 0:pi/100:2*pi; y1 = sin(2*x); y2 = 2*cos(2*x); plot(x,y1,'k-', x, y2,'b--'), … grid on title('f(x) = sin(2x) and its Derivative'); xlabel('x'); ylabel('y'); legend('f(x)', 'd/dx (fx)')

Sept. 26, 2005 Lecture 6 - By Paul Lin Logarithmic Scales Log Scale plots Log Scale plots Decibel Db = 10log(Pout/Pin)Decibel Db = 10log(Pout/Pin) Frequency response plotFrequency response plot MATLAB Functions MATLAB Functions semilogx(x,y) – plot x data on log scale and y data on linear scalesemilogx(x,y) – plot x data on log scale and y data on linear scale semilogy(x,y) – plot x data on linear scale and y on log scalesemilogy(x,y) – plot x data on linear scale and y on log scale Loglog(x,y) – plot both x and y data on log scaleLoglog(x,y) – plot both x and y data on log scale

Sept. 26, 2005 Lecture 6 - By Paul Lin Plotting Applications Example 6-5: Mr. A performed an electrical circuit experiment and collected the following measured resistance values (ohms) and current values (amperes): Example 6-5: Mr. A performed an electrical circuit experiment and collected the following measured resistance values (ohms) and current values (amperes): R = 0.5, 0.75, 1.0, 2.0, 3.0, 4.0 I = 10, 7, 5.2, 3, 1.8, 1.5 You are asked to help Mr. A to prepare data and generate a plot that shows red circles on all data points You are asked to help Mr. A to prepare data and generate a plot that shows red circles on all data points

Sept. 26, 2005 Lecture 6 - By Paul Lin Plotting Applications (continue) Example 6-5: Solution Example 6-5: Solution %plotRI.m %Author: M. Lin %Date: 9/1/04 %Version: 1.0 %Description: % R = % I = R = [ ]; I = [ ]; plot(R,I, 'ro--') % show red circles at the data points xlabel('Resistance'), ylabel('Current') title('R vs I Plot')

Sept. 26, 2005 Lecture 6 - By Paul Lin Plotting Application (continue) Example 6-6: Mr. A performed an Ohm’s experiment and collected the following measured voltage values (volts) and current values (milli-amperes): Example 6-6: Mr. A performed an Ohm’s experiment and collected the following measured voltage values (volts) and current values (milli-amperes): V = 0, 1, 2, 3, 4, 5, 6, 7, 8 I = 10, 8, 7, 7, 6, 4. 3, 2, 0 You are asked to help Mr. A to prepare data and generate a plot that shows red-lines and blue circles on all data points You are asked to help Mr. A to prepare data and generate a plot that shows red-lines and blue circles on all data points

Sept. 26, 2005 Lecture 6 - By Paul Lin Plotting Applications (continue) Example 6-6: Solution %plotVI.m %Author: M. Lin %Date: 9/1/04 %Version: 1.0 %Description: % V (volts) = % I (milliamps) = V = [ ]; I = [ ]; plot(V,I, 'r--', V, I, 'bo') % show red cicrles at the data points xlabel('Voltage - Volt'), ylabel('Current - milliamps') title(‘E - I Plot')

Sept. 26, 2005 Lecture 6 - By Paul Lin Plotting Applications Example 6-7: Maximum Power Transfer. A voltage source E = 120 v with an internal resistance of Rs of 50 ohms supplying a load of resistance RL. Example 6-7: Maximum Power Transfer. A voltage source E = 120 v with an internal resistance of Rs of 50 ohms supplying a load of resistance RL. Q1 - Find the value of load resistance RL that will result in the maximum possible power being supplied by the source to the load. Q1 - Find the value of load resistance RL that will result in the maximum possible power being supplied by the source to the load. Q2 – How much power be supplied in this case? Q2 – How much power be supplied in this case? Q3 – Plot the power supply to the load as a function of the load resistance RL. Q3 – Plot the power supply to the load as a function of the load resistance RL.

Sept. 26, 2005 Lecture 6 - By Paul Lin Plotting Applications Example 6-7: Solution: Example 6-7: Solution: Circuit Diagram Circuit Diagram Equations Equations PL = I 2 RL, where I is the current passing through the circuit. I = E/R total = E/(Rs + RL) Array data for MALAB plotting Array data for MALAB plotting RL – a vectorRL – a vector E and Rs are scalarsE and Rs are scalars

Sept. 26, 2005 Lecture 6 - By Paul Lin Plotting Applications Example 6-7: Solution: Example 6-7: Solution: MATLAB Program MATLAB Program %maxPower_p67.m Rs = 50; E = 120; RL = 1:1:100; I = E./(Rs + RL); % NOT I = R/(Rs + RL) % -- for Scalar calculation PL = (I.^2).* RL; % NOT PL = I^2 * RL % -- for Scalar calculation plot(RL, PL), grid on title('Max Power Transfer'); xlabel('Load resistance RL'); ylabel('Power - Watts');

Sept. 26, 2005 Lecture 6 - By Paul Lin Plotting Applications Example 6-7: Solution: Example 6-7: Solution: Answers Answers Q1 – Find the value of RL for Pmax to occur Q1 – Find the value of RL for Pmax to occur RL = 50 ohms results a PL max of 72 wattsRL = 50 ohms results a PL max of 72 watts Q2 – How much power be supplied in this case? Q2 – How much power be supplied in this case? PL consume 72 Watt,PL consume 72 Watt, Rs will also receive the same 72 Watts inside the power supplyRs will also receive the same 72 Watts inside the power supply Power supplied is 144 wattsPower supplied is 144 watts Q3 – Plot the PL(RL) Q3 – Plot the PL(RL) 72 watts

Sept. 26, 2005 Lecture 6 - By Paul Lin 23 Summary Introduction to Plotting Introduction to Plotting Simple X-Y Plots Simple X-Y Plots Printing a PlotPrinting a Plot Exporting a Plot as a Graphical ImageExporting a Plot as a Graphical Image Line Color, Style, Marker and LegendsLine Color, Style, Marker and Legends Multiple Plot Multiple Plot Logarithmic Scales Logarithmic Scales Plotting Applications Plotting Applications