Recap Functions with No input OR No output Determining The Number of Input and Output Arguments Local Variables Global Variables Creating ToolBox of Functions.

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 14 User-defined functions Function: concept, syntax, and examples © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Lecture 5.
Chapter 18 Interpolation The Islamic University of Gaza
CITS2401 Computer Analysis & Visualisation
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.
ME457 Mechatronic System Modeling MICHIGAN STATE UNIVERSITY Matlab® refresher Your objective: to dominate! My objective: to help you dominate!
Introduction to programming in MATLAB MATLAB can be thought of as an super-powerful graphing calculator Remember the TI-83 from calculus? With many more.
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
CMPS1371 Introduction to Computing for Engineers NUMERICAL METHODS.
MATLAB File Management. MATLAB User File Management Matlab provides a group of commands to manage user files. For more information, type help iofun. pwd.
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.
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.
Simpson Rule For Integration.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
Hydroinformatics: Session4 Dr Ivan Stoianov Room 328B Dr Andrew Ireson (Room 304) Mr Juan Rodriguez-Sanchez (411A) Mr Baback.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
Recap Summary of Chapter 6 Interpolation Linear Interpolation.
Numerical Methods Part: Simpson Rule For Integration.
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.
Chapter 4 "Inheritance" Inheritance is a powerful feature that allows the reuse of code. However, be sure that functions applied to objects created at.
Recap Function M-files Syntax of Function M-Files Comments Multiple Input and Output Functions.
Introduction To this point MATLAB has been used to answer questions with a numeric value ▫Variables are assigned specific values ▫Answers are numbers MATLAB.
MATLAB Harri Saarnisaari, Part of Simulations and Tools for Telecommunication Course.
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
Covenant College November 27, Laura Broussard, Ph.D. Professor COS 131: Computing for Engineers Chapter 5: Functions.
Recap Saving Plots Summary of Chapter 5 Introduction of Chapter 6.
1 Lecture 1 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Numerical Analysis 3D Plots. A numerical method is a technique for computing a numerical approximation of the solution to a mathematical problem.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
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.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Chapter 15 General Least Squares and Non- Linear.
1 Lecture 4 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
1 Lecture 5 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
ENG College of Engineering Engineering Education Innovation Center 1 Functions 1 in MATLAB Topics Covered: 1.Uses of Functions Organizational Tool.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
Chapter 4 Minitab Recipe Cards. Correlation coefficients Enter the data from Example 4.1 in columns C1 and C2 of the worksheet.
1 Lecture 8 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 4 Chapter 17 and 18 Interpolation.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 6 - Chapters 22 and 23.
ENG College of Engineering Engineering Education Innovation Center 1 Functions 2 in MATLAB Topics Covered: 1.Functions in Script Files Inline Functions.
MATLAB ® for Engineers, Holly Moore Fourth Edition, Global Edition © Pearson Education Limited 2015 All rights reserved. Figure 13.1 Interpolation between.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Chapter 21 Numerical Differentiation.
Lecture 29: Modeling Data. Data Modeling Interpolate between data points, using either linear or cubic spline models Model a set of data points as a polynomial.
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Graphing Linear Equations
ECE 1304 Introduction to Electrical and Computer Engineering
Matlab Training Session 4: Control, Flow and Functions
Lecture 25.
Introduction to MATLAB for Engineers, Third Edition
User Defined Functions
StatLab Matlab Workshop
Use of Mathematics using Technology (Maltlab)
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Your objective: to dominate! My objective: to help you dominate!
Presentation transcript:

Recap Functions with No input OR No output Determining The Number of Input and Output Arguments Local Variables Global Variables Creating ToolBox of Functions Anonymous Functions and Function Handles Function Functions Subfunctions

Summary of Chapter 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

Introduction Interpolate between data points, using either linear or cubic spline models Model a set of data points as a polynomial Use the basic fitting tool Use the curve-fitting toolbox Perform numerical differentiations Perform numerical integrations Solve differential equations numerically

Interpolation Especially when we measure things, we don’t gather data at every possible data point Consider a set of x–y data collected during an experiment By using an interpolation technique, we can estimate the value of y at values of x where we didn’t take measurement The two most common interpolation techniques are Linear interpolation Cubic spline interpolation both of which are supported by MATLAB

Interpolation between data points

Linear Interpolation The most common way to estimate a data point between two known points is linear interpolation In this technique, we assume that the function between the points can be estimated by a straight line drawn between them If we find the equation of a straight line defined by the two known points, we can find y for any value of x The closer together the points are, the more accurate our approximation is likely to be

Continued…. We can perform linear interpolation in MATLAB with the interp1 function We’ll first need to create a set of ordered pairs to use as input to the function The data used to create the right-hand graph of next figure is x = 0:5; y = [15, 10, 9, 6, 2, 0];

Continued…. To perform a single interpolation, the input to interp1 is the x data, the y data, and the new x value for which you’d like an estimate of y For example: to estimate the value of y when x is equal to 3.5, type interp1(x,y,3.5) ans = 4 You can perform multiple interpolations all at the same time by putting a vector of x -values in the third field of the interp1 function For example: to estimate y -values for new x ’s spaced evenly from 0 to 5 by 0.2, type new_x = 0:0.2:5; new_y = interp1(x,y,new_x) which returns new_y = Columns 1 through Columns 6 through Columns 11 through Columns 16 through Columns 21 through Column 26 0 Graph is plotted as plot(x,y,new_x,new_y,'o')

Continued…. The interp1 function defaults to linear interpolation to make its estimates. However, other approaches are possible If we want (probably for documentation purposes) to explicitly define the approach used in interp1 as linear interpolation, we can specify it in a fourth field: interp1(x, y, 3.5, 'linear') ans = 4