Chapter 4 "Inheritance" Inheritance is a powerful feature that allows the reuse of code. However, be sure that functions applied to objects created at.

Slides:



Advertisements
Similar presentations
MathCAD Data.
Advertisements

MATLAB – A Computational Methods By Rohit Khokher Department of Computer Science, Sharda University, Greater Noida, India MATLAB – A Computational Methods.
Lecture 5.
CITS2401 Computer Analysis & Visualisation
By Hrishikesh Gadre Session II Department of Mechanical Engineering Louisiana State University Engineering Equation Solver Tutorials.
MathCAD Data. Data in tables Tables are analogous to matrix The numbers of columns and rows can be dynamically changed (in contrast to matrix) To enter.
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
SPSS Statistical Package for the Social Sciences is a statistical analysis and data management software package. SPSS can take data from almost any type.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
MATLAB Fundamentals.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
Data processing in MathCAD. Data in tables Tables are analogous to matrices Tables are analogous to matrices The numbers of columns and rows can be dynamically.
Computer Literacy BASICS
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
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.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
Recap Graphic Window Edit Window Start Button Matrices in MATLAB Scalar Operations Order of Operations Array Operations Matrix Addition Matrix Multiplication.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
MATLAB An Introduction to MATLAB (Matrix Laboratory) 1.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
Recap Summary of Chapter 6 Interpolation Linear Interpolation.
Copyright © The McGraw-Hill Companies, Inc. Introduction to MATLAB for Engineers, Third Edition William J. Palm III Chapter 1 An Overview of MATLAB.
Department of Mechanical Engineering, LSU Session IV MATLAB Tutorials Session IV Mathematical Applications using MATLAB Rajeev Madazhy
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
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.
Recap Sum and Product Functions Matrix Size Function Variance and Standard Deviation Random Numbers Complex Numbers.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
ES 240: Scientific and Engineering Computation. Chapter 2 Chapter 2: MATLAB Fundamentals Uchechukwu Ofoegbu Temple University.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
1 DKT 211 Basic Communication Engineering LAB # 1A : (Lecture 1) Introduction to Matlab  Basic Features  Scientific features  Array Operations  Script.
Recap Saving Plots Summary of Chapter 5 Introduction of Chapter 6.
Part 1 Chapter 2 MATLAB Fundamentals PowerPoints organized by Dr. Michael R. Gustafson II, Duke University and Prof. Steve Chapra, Tufts University All.
Recap Chapter 5 “Plotting” Two Dimensional Plots Simple x-y Plots Titles, Labels and Grids Multiple Plots.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Recap Cubic Spline Interpolation Multidimensional Interpolation Curve Fitting Linear Regression Polynomial Regression The Polyval Function The Interactive.
Polynomials, Curve Fitting and Interpolation. In this chapter will study Polynomials – functions of a special form that arise often in science and engineering.
MATLAB for Engineers, by Holly Moore. ISBN © 2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Chapter 15 General Least Squares and Non- Linear.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Recap Functions with No input OR No output Determining The Number of Input and Output Arguments Local Variables Global Variables Creating ToolBox of Functions.
Matlab for Engineers Matlab Environment Chapter 2.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
MATLAB ® for Engineers, Holly Moore Fourth Edition, Global Edition © Pearson Education Limited 2015 All rights reserved. Figure 5.1 Simple Plot of Time.
“Moh’d Sami” AshhabSummer 2008University of Jordan MATLAB By (Mohammed Sami) Ashhab University of Jordan Summer 2008.
MATLAB ® for Engineers, Holly Moore Fourth Edition, Global Edition © Pearson Education Limited 2015 All rights reserved. Figure 13.1 Interpolation between.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
1-2 What is the Matlab environment? How can you create vectors ? What does the colon : operator do? How does the use of the built-in linspace function.
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
ECE 1304 Introduction to Electrical and Computer Engineering
Lecture 25.
Two-Dimensional Plots
User Defined Functions
Communication and Coding Theory Lab(CS491)
Presentation transcript:

Chapter 4 "Inheritance" Inheritance is a powerful feature that allows the reuse of code. However, be sure that functions applied to objects created at run time through the new operator are bound at run time. This feature is known as dynamic binding, and the use of virtual functions is required to ensure that run-time decisions are made. Reread this chapter as often as necessary to ensure that you understand the distinctions among non-virtual functions virtual functions pure virtual functions

Chapter 6 “Algorithm Analysis" In this chapter we introduced algorithm analysis and showed that algorithmic decisions generally influence the running time of a program much more than programming tricks do We also showed the huge difference between the running times for quadratic and linear programs and illustrated that cubic algorithms are, for the most part, unsatisfactory We examined an algorithm that could be viewed as the basis for our first data structure The binary search efficiently supports static operations thereby providing a logarithmic worst-case search Later in the text we examine dynamic data structures that efficiently support updates

Data Visualization with MATLAB Chapter 2 “MATLAB Environment” Chapter 3 “Built-in MATLAB Functions” Chapter 5 “Plotting” Chapter 6 “User-Defined Functions” Chapter 13 “Numerical Techniques”

Chapter 2 "MATLAB Environment" In this chapter, we introduced the basic MATLAB structure The MATLAB environment includes multiple windows, four of which are open in the default view: Command window Command history window Workspace window Current folder window In addition, the Document window Graphics window Edit window open as needed during a MATLAB session

Continued…. Variables defined in MATLAB follow common computer naming conventions: Names must start with a letter. Letters, numbers, and the underscore are the only characters allowed. Names are case sensitive. Names may be of any length, although only the first 63 characters are used by MATLAB Some keywords are reserved by MATLAB and cannot be used as variable names MATLAB allows the user to reassign function names as variable names, although doing so is not good practice. The basic computational unit in MATLAB is the matrix. Matrices may be Scalars ( 1 x 1 matrix) Vectors ( 1 x n or n x 1 matrix, either a row or a column) Two-dimensional arrays ( m x n or n x m ) Multidimensional arrays

Continued…. Matrices often store numeric information, although they can store other kinds of information as well Data can be entered into a matrix manually or can be retrieved from stored data files When entered manually, a matrix is enclosed in square brackets, elements in a row are separated by either commas or spaces, and a new row is indicated by a semicolon: a = [ ; ] Evenly spaced matrices can be generated with the colon operator. Thus, the command b = 0:2:10 creates a matrix starting at 0, ending at 10, and with an increment of 2 The linspace and logspace functions can be used to generate a matrix of specified length from given starting and ending values, spaced either linearly or logarithmically The help function or the MATLAB Help menu can be used to determine the appropriate syntax for these and other functions

Continued…. MATLAB follows the standard algebraic order of operations MATLAB supports both standard (decimal) and scientific notation It also supports a number of different display options. No matter how values are displayed, they are stored as double-precision floating- point numbers MATLAB variables can be saved or imported from either.MAT or.DAT files The.MAT format is proprietary to MATLAB and is used because it stores data more efficiently than other file formats The.DAT format employs the standard ASCII format and is used when data created in MATLAB will be shared with other programs Collections of MATLAB commands can be saved in script M-files. This is the best way to save the list of commands used to solve a problem so that they can be reused at a later time Cell mode allows the programmer to group M-file code into sections and to run each section individually. It is especially convenient when one M-file is used to solve multiple problems.

Chapter 3 “Built-in MATLAB Functions" General mathematical functions, such as exponential functions logarithmic functions roots Rounding functions Functions used in discrete mathematics, such as factoring functions prime-number functions Trigonometric functions, including standard trigonometric functions inverse trigonometric functions hyperbolic trigonometric functions trigonometric functions that use degrees instead of radians

Continued…. Data analysis functions, such as maxima and minima averages (mean and median) sums and products sorting standard deviation and variance Random-number generation for both uniform distributions Gaussian (normal) distributions Functions used with complex numbers

Chapter 5 “Plotting" The most commonly used graph in engineering is the x – y plot This two-dimensional plot can be used to graph data or to visualize mathematical functions No matter what a graph represents, it should always include a title and x - and y -axis labels Axis labels should be descriptive and should include units, such as ft/s or kJ/kg MATLAB includes extensive options for controlling the appearance of your plots The user can specify the color, line style, and marker style for each line on a graph A grid can be added to the graph, and the axis range can be adjusted Text boxes and a legend can be employed to describe the graph The subplot function is used to divide the plot window into an mxn grid Inside each of these subwindows, any of the MATLAB plots can be created and modified

Continued…. In addition to x – y plots, MATLAB offers a variety of plotting options, including polar plots, pie charts, bar graphs, histograms, and x – y graphs with two y –axes The scaling on x – y plots can be modified to produce logarithmic plots on either or both x – and y- axes Engineers often use logarithmic scaling to represent data as a straight line The function fplot allows the user to plot a function without defining a vector of x - and y –values MATLAB automatically chooses the appropriate number of points and spacing to produce a smooth graph Additional function-plotting capability is available in the symbolic toolbox

Continued…. The three-dimensional plotting options in MATLAB include a line plot, a number of surface plots, and contour plots Most of the options available in two dimensional plotting also apply to these three-dimensional plots The meshgrid function is especially useful in creating three- dimensional surface plots Interactive tools allow the user to modify existing plots These tools are available from the figure menu bar Plots can also be created with the interactive plotting option from the workspace window The interactive environment is a rich resource Figures created in MATLAB can be saved in a variety of ways, either to be edited later or to be inserted into other documents MATLAB offers both proprietary file formats that minimize the storage space required to store figures and standard fi le formats suitable to import into other applications

Chapter 6 “User Defined Functions" MATLAB contains a wide variety of built-in functions However, you will often find it useful to create your own MATLAB functions The most common type of user-defined MATLAB function is the function M-file, which must start with a function-definition line that contains the word function a variable that defines the function output a function name a variable used for the input argument For example, function output = my_function(x)

Continued…. The function name must also be the name of the M-file in which the function is stored Function names follow the standard MATLAB naming rules Like the built-in functions, user-defined functions can accept multiple inputs and can return multiple results Comments immediately following the function-definition line can be accessed from the command window with the help command Variables defined within a function are local to that function. They are not stored in the workspace and cannot be accessed from the command window Global variables can be defined with the global command used in both the command window and a MATLAB function. Good programming style suggests that define global variables with capital letters. In general, however, it is not wise to use global variables

Continued…. Groups of user-defined functions, called “toolboxes,” may be stored in a common directory and accessed by modifying the MATLAB® search path. This is accomplished interactively with the path tool, either from the menu bar, as in File -> Set Path or from the command line, with pathtool MATLAB provides access to numerous toolboxes developed at The MathWorks or by the user community Another type of function is the anonymous function, which is defined in a MATLAB session or in a script M-file and exists only during that session Anonymous functions are especially useful for very simple mathematical expressions or as input to the more complicated function functions

Chapter 13 “Numerical Techniques" Tables of data are useful for summarizing technical information However, if a value is needed that is not included in the table, must approximate that value by using some sort of interpolation technique MATLAB includes such a technique, called interp1. This function requires three inputs: a set of x -values, a corresponding set of y -values, and a set of x -values for which you would like to estimate y -values The function defaults to a linear interpolation technique, which assumes that approximate these intermediate y -values as a linear function of x that is, y = f(x) = ax + b

Continued…. A different linear function is found for each set of two data points, ensuring that the line approximating the data always passes through the tabulated points The interp1 function can also model the data by using higher-order approximations, the most common of which is the cubic spline The approximation technique is specified as a character string in a fourth optional field of the interp1 function If it’s not specified, the function defaults to linear interpolation. An example of the syntax is new_y = interp1(tabulated_x, tabulated_y, new_x, 'spline')

Continued…. In addition to the interp1 function, MATLAB includes a two- dimensional interpolation function called interp2, a three- dimensional interpolation function called interp3, and a multidimensional interpolation function called interpn Curve-fitting routines are similar to interpolation techniques However, instead of connecting data points, they look for an equation that models the data as accurately as possible Once you have an equation, you can calculate the corresponding values of y The curve that is modeled does not necessarily pass through the measured data points MATLAB’s curve-fitting function is called polyfit and models the data as a polynomial by means of a least-squares regression technique

Continued….

MATLAB also includes an interactive curve-fitting capability that allows the user to model data not only with polynomials, but with more complicated mathematical functions The basic curve-fitting tools can be accessed from the Tools menu in the figure window More extensive tools are available in the curve-fitting toolbox, which is accessed by typing cftool in the command window. Numerical techniques are used widely in engineering to approximate both derivatives and integrals Derivatives and integrals can also be found with the symbolic toolbox The MATLAB diff function finds the difference between values in adjacent elements of a vector By using the diff function with vectors of x - and y -values, we can approximate the derivative with the command slope = diff(y)./diff(x) The more closely spaced the x and y data are, the closer will be the approximation of the derivative

Continued…. The gradient function uses a forward difference approach to approximate the derivative at the first point in an array It uses a backward difference approach for the final value in the array, and a central difference approach for the remainder of the points In general, the central difference approach gives a more accurate approximation of the derivative than either of the other two techniques Integration of ordered pairs of data is accomplished using the trapezoidal rule, with the trapz function This approach can also be used with functions, by creating a set of ordered pairs based on a set of x values and the corresponding y values

Continued….

MATLAB includes a series of solver functions for first-order ordinary differential equations and systems of equations All of the solver functions use the common format [t,y] = odesolver(function_handle,[initial_time, final_time], [initial_cond_array]) A good first try is usually the ode45 solver function, which uses a Runge–Kutta technique Other solver functions have been formulated for stiff differential equations and implicit formulations The ode solver functions require that the user know the initial conditions for the problem If, instead, boundary conditions are known at other than the starting conditions, the bvp4 function should be used