January 24, 2005 Lecture 3 - By P. Lin 1 CPET 190 Lecture 3 Problem Solving with MATLAB

Slides:



Advertisements
Similar presentations
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
Advertisements

Lecture 7 Debugging Code & Data Import/Export © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Introduction to Matlab Tutorial for CS4MN3/SE3X03 Wen Yu McMaster University.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/22/2003.
Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = B = >> X = A\B X =
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
Introduction to MATLAB
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.
ME457 Mechatronic System Modeling MICHIGAN STATE UNIVERSITY Matlab® refresher Your objective: to dominate! My objective: to help you dominate!
Introduction to R Statistical Software Anthony (Tony) R. Olsen USEPA ORD NHEERL Western Ecology Division Corvallis, OR (541)
Digital Image Processing Lecture3: Introduction to MATLAB.
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine
Lecture 13: M/O/F/ for Engineering Applications - Part 1 BJ Furman 26NOV2012.
M-files While commands can be entered directly to the command window, MATLAB also allows you to put commands in text files called M- files. M-files are.
MATLAB File Management. MATLAB User File Management Matlab provides a group of commands to manage user files. For more information, type help iofun. pwd.
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
You can make this in matlab!. Matlab Introduction and Matrices.
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.
IC3003 B ASIC S CIENTIFIC C OMPUTING Lecture 1 Monday 08:30-11:30 U204a.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
INTRODUCTION TO MATLAB LAB# 01
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
Copyright © The McGraw-Hill Companies, Inc. Introduction to MATLAB for Engineers, Third Edition William J. Palm III Chapter 1 An Overview of MATLAB.
Chapter 1: Getting Started with MATLAB MATLAB for Scientist and Engineers Using Symbolic Toolbox.
1 MatLab Basics Jae Hoon Kim Department of Physics Kangwon National University It contains hundreds of commands to do mathematics. Graph functions, solve.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
CMPS 1371 Introduction to Computing for Engineers MatLab.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
What Matlab can do for me? Matlab stands for MATrix LABoratory Matlab is a software package for high-performance numerical computation and visualization.
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 &
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
Engineering Analysis – Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
CSE123 Lecture 3 Files and File ManagementScripts.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
The Hong Kong Polytechnic University Industrial Centre MatLAB Lesson 1 : Overview & Environment Edward Cheung Room W311g.
Digital Image Processing Introduction to MATLAB. Background on MATLAB (Definition) MATLAB is a high-performance language for technical computing. The.
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 4 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
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)
BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology Taxila.
An Introduction to Programming in Matlab Emily Blumenthal
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 The name of MATLAB stands for matrix laboratory. Starting a MATLAB Session -On Microsoft® Windows® platforms, start the MATLAB program by double-clicking.
Matlab Programming for Engineers
Release Numbers MATLAB is updated regularly
MATLAB Basics Nafees Ahmed Asstt. Professor, EE Deptt DIT, DehraDun.
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Use of Mathematics using Technology (Maltlab)
Digital Image Processing
Matlab.
Matlab Basic Dr. Imtiaz Hussain
Your objective: to dominate! My objective: to help you dominate!
Presentation transcript:

January 24, 2005 Lecture 3 - By P. Lin 1 CPET 190 Lecture 3 Problem Solving with MATLAB

January 24, 2005 Lecture 3 - By P. Lin 2 Lecture 3: MATLAB Development Environment 3-1 Desktop Tools 3-1 Desktop Tools Starting and Quitting MATLABStarting and Quitting MATLAB Command WindowCommand Window Running Functions Running Functions Entering Variables Entering Variables Controlling Input/Output Controlling Input/Output Searching Items Searching Items Running Programs Running Programs Preferences for the Command Window Preferences for the Command Window

January 24, 2005 Lecture 3 - By P. Lin 3 Lecture 3: MATLAB Development Environment (continue) 3-1 Desktop Tools (continue) 3-1 Desktop Tools (continue) Command HistoryCommand History The MATLAB WorkspaceThe MATLAB Workspace Help BrowserHelp Browser Workspace BrowserWorkspace Browser Current Directory BrowserCurrent Directory Browser Edit/DebugEdit/Debug

January 24, 2005 Lecture 3 - By P. Lin 4 Lecture 3: MATLAB Development Environment (continue) 3-2 Useful Commands 3-2 Useful Commands The MATLAB Search PathThe MATLAB Search Path Number Display FormatsNumber Display Formats Session LogSession Log MATLAB Managing Commands and FunctionsMATLAB Managing Commands and Functions demo - Run demos demo - Run demos help- Online help help- Online help ver - Current MATLAB and toolbox versions ver - Current MATLAB and toolbox versions version - Current MATLAB version number version - Current MATLAB version number path- MATLAB Search path path- MATLAB Search path diary- Save typed commands on a named file diary- Save typed commands on a named file Summary Summary

January 24, 2005 Lecture 3 - By P. Lin 5 Starting and Quitting MATLAB Starting MATLAB From command window: start -> Run -> MATLAB From command window: start -> Run -> MATLAB Start -> All Programs -> MATLAB Start -> All Programs -> MATLAB

January 24, 2005 Lecture 3 - By P. Lin 6 Starting and Quitting MATLAB Quitting MATLAB At the MATLAB command window: At the MATLAB command window: >> quit >> exit Close MATLAB Window Close MATLAB Window

January 24, 2005 Lecture 3 - By P. Lin 7 Desktop Tools Started MATLAB and see the three sub-windows: Command Window Command Window Current Directory Current Directory Command History Command History At the command window, we enter >>help help

January 24, 2005 Lecture 3 - By P. Lin 8 Command Window Running Functions Running Functions Entering Variables Entering Variables Controlling Input/Output Controlling Input/Output Searching Items Searching Items Running Programs Running Programs Setting Preferences for the Command Window Setting Preferences for the Command Window

January 24, 2005 Lecture 3 - By P. Lin 9 Running Commands An Example: >> magic(3) ans = >> help magic MAGIC Magic square. MAGIC Magic square. MAGIC(N) is an N-by-N matrix constructed from the integers MAGIC(N) is an N-by-N matrix constructed from the integers 1 through N^2 with equal row, column, and diagonal sums. 1 through N^2 with equal row, column, and diagonal sums. Produces valid magic squares for all N > 0 except N = 2. Produces valid magic squares for all N > 0 except N = 2. 15

January 24, 2005 Lecture 3 - By P. Lin 10 Entering Variables >> x = 10 x = 10 >> y = 10 y = 10 >> x * y ans = 100 >> x / y ans = 1 >> x + y ans = 20 >> x - y ans = 0 >>

January 24, 2005 Lecture 3 - By P. Lin 11 Controlling Input/Output Format Function – control the display formats for numeric values Format Function – control the display formats for numeric values Examples Examples >> x = 1/3 x = x = >> y = e-7 y = e-7 y = e-7 >> format short e >> x x = e-001 >> y y = e-007 Hit Enter key MATLAB Displays Hit Enter key MATLAB Displays Hit Enter key Enter x Enter y MATLAB Echoes

January 24, 2005 Lecture 3 - By P. Lin 12 Controlling Input/Output (continue) Format Function: Format Function: >> help format FORMAT Set output format. FORMAT Set output format. All computations in MATLAB are done in double precision. All computations in MATLAB are done in double precision. FORMAT may be used to switch between different output FORMAT may be used to switch between different output display formats as follows: display formats as follows: FORMAT Default. Same as SHORT. FORMAT Default. Same as SHORT. FORMAT SHORT Scaled fixed point format with 5 digits. FORMAT SHORT Scaled fixed point format with 5 digits. FORMAT LONG Scaled fixed point format with 15 digits. FORMAT LONG Scaled fixed point format with 15 digits. FORMAT SHORT E Floating point format with 5 digits. FORMAT SHORT E Floating point format with 5 digits. FORMAT LONG E Floating point format with 15 digits. FORMAT LONG E Floating point format with 15 digits. >> format long >> x x = >> y y = e- 007

January 24, 2005 Lecture 3 - By P. Lin 13 Controlling Input/Output (continue) Format Function: Format Function: >> help format … FORMAT SHORT G Best of fixed or floating point format with 5 digits. … FORMAT SHORT G Best of fixed or floating point format with 5 digits. FORMAT LONG G Best of fixed or floating point format with 15 digits. FORMAT LONG G Best of fixed or floating point format with 15 digits. FORMAT HEX Hexadecimal format. FORMAT HEX Hexadecimal format. FORMAT + The symbols +, - and blank are printed for positive, negative and zero elements. Imaginary parts are ignored. FORMAT + The symbols +, - and blank are printed for positive, negative and zero elements. Imaginary parts are ignored. FORMAT BANK Fixed format for dollars and cents. FORMAT BANK Fixed format for dollars and cents. FORMAT RAT Approximation by ratio of small integers. FORMAT RAT Approximation by ratio of small integers. >> format long g >> x x = >> y y = e- 007 >> format bank >> x x = 0.33 >> y y = 0.00 >> format rat >> x x = 1/3 >> y y = 1/

January 24, 2005 Lecture 3 - By P. Lin 14 Controlling Input/Output (continue) File -> Preferences Allows you to set up various numeric display formats through GUIAllows you to set up various numeric display formats through GUI

January 24, 2005 Lecture 3 - By P. Lin 15 Suppress Output Suppressing Output Suppressing Output End of the statement with a semicolonEnd of the statement with a semicolon Increase statement and program execution speedIncrease statement and program execution speed An Example An Example >> x = 10; >> y = 10; >> product = x * y Product = 100

January 24, 2005 Lecture 3 - By P. Lin 16 Entering long Statements If a statement does not fit on a line (too long), uses an ellipsis (three periods), follow by Enter or Return, to indicate the continuation of the statement to the next line If a statement does not fit on a line (too long), uses an ellipsis (three periods), follow by Enter or Return, to indicate the continuation of the statement to the next line For an example For an example >> x = x = 51 51

January 24, 2005 Lecture 3 - By P. Lin 17 Command Line Editing and Command History Command Line Editing Command Line Editing Keys such as right arrow →, down arrow ↓, up arrow ↑, left arrow ←, etc, can be used to edit commands Command History Command History The entered commands at the Command Windows are recorded or logged in the Command HistoryThe entered commands at the Command Windows are recorded or logged in the Command History We can view previous commands or statementsWe can view previous commands or statements We can copy or execute rerun previous statementsWe can copy or execute rerun previous statements

January 24, 2005 Lecture 3 - By P. Lin 18 The MATLAB Workspace who function who function whos function whos function clear function clear function >> who Your variables are: x y >> whos Name Size Bytes Class x 1x1 8 double array y 1x1 8 double array Grand total is 2 elements using 16 bytes >> clear x >> who Your variables are: y >> clear >> whos

January 24, 2005 Lecture 3 - By P. Lin 19 The MATLAB Workspace save function save function load function load function >> save 8_20_2004.mat >> clear >> whos >> load 8_20_2004.mat >> whos Name Size Bytes Class ans 1x1 8 double array x 1x1 8 double array y 1x1 8 double array Grand total is 3 elements using 24 bytes >> clear >> whos Current Directory

January 24, 2005 Lecture 3 - By P. Lin 20 Save Command We can use “help save” to see documentation of SAVE function and learn how to Save workspace variables to disk. We can use “help save” to see documentation of SAVE function and learn how to Save workspace variables to disk. SAVE FILENAME saves all workspace variables to the binary "MAT-file“, If FILENAME has no extension,.mat is assumed.SAVE FILENAME saves all workspace variables to the binary "MAT-file“, If FILENAME has no extension,.mat is assumed. SAVE, by itself, creates the binary "MAT-file" named 'matlab.mat'. It is an error if 'matlab.mat' is not writable. SAVE, by itself, creates the binary "MAT-file" named 'matlab.mat'. It is an error if 'matlab.mat' is not writable. SAVE FILENAME X saves only X. SAVE FILENAME X saves only X. SAVE FILENAME X Y Z saves X, Y, and Z. The wildcard '*' can be used to save only those variables that match a pattern. SAVE FILENAME X Y Z saves X, Y, and Z. The wildcard '*' can be used to save only those variables that match a pattern.

January 24, 2005 Lecture 3 - By P. Lin 21 Save Command (continue) MATLAB also offers various saving options: ASCII Options: ASCII Options: SAVE... -ASCII uses 8-digit ASCII form instead of binary regardless of file extension.SAVE... -ASCII uses 8-digit ASCII form instead of binary regardless of file extension. SAVE... -ASCII -DOUBLE uses 16-digit ASCII form.SAVE... -ASCII -DOUBLE uses 16-digit ASCII form. SAVE... -ASCII -TABS delimits with tabs.SAVE... -ASCII -TABS delimits with tabs. And more will be discussed later And more will be discussed later

January 24, 2005 Lecture 3 - By P. Lin 22 Help Browser

January 24, 2005 Lecture 3 - By P. Lin 23 Workspace Browser

January 24, 2005 Lecture 3 - By P. Lin 24 Current Directory Browser

January 24, 2005 Lecture 3 - By P. Lin 25 The Edit/Debug Use the Editor/Debugger to create and debug M-files, which are programs you write to run MATLAB functions. Use the Editor/Debugger to create and debug M-files, which are programs you write to run MATLAB functions. The Editor/Debugger provides a graphical user interface for basic text editing, as well as for M-file debugging. The Editor/Debugger provides a graphical user interface for basic text editing, as well as for M-file debugging.

January 24, 2005 Lecture 3 - By P. Lin 26 The Edit/Debug (continue)

January 24, 2005 Lecture 3 - By P. Lin 27 The Edit/Debug (continue) Create a mlab_exs directory Save the M-file as sine60hz.m

January 24, 2005 Lecture 3 - By P. Lin 28 The Edit/Debug (continue)

January 24, 2005 Lecture 3 - By P. Lin 29 Testing/Debugging sin60hz.m Click -> Debug -> Run

January 24, 2005 Lecture 3 - By P. Lin 30 Other Commands Other Useful MATLAB Management Commands/Functions Other Useful MATLAB Management Commands/Functions demo - Run demos demo - Run demos help- Online help help- Online help ver- Current MATLAB and toolbox versions ver- Current MATLAB and toolbox versions version - Current MATLAB version number version - Current MATLAB version number path- MATLAB Search path path- MATLAB Search path diary - Save typed commands on a named file diary - Save typed commands on a named file

January 24, 2005 Lecture 3 - By P. Lin 31 Summary Desktop Tools Desktop Tools Starting and Quitting MATLAB Starting and Quitting MATLAB Command Window Command Window Running FunctionsRunning Functions Entering VariablesEntering Variables Controlling Input/OutputControlling Input/Output Searching ItemsSearching Items Running ProgramsRunning Programs Preferences for the Command WindowPreferences for the Command Window Command History Command History The MATLAB Workspace The MATLAB Workspace Help Browser Help Browser Workspace Browser Workspace Browser Current Directory Browser Current Directory Browser Edit/Debug - a sine wave program Edit/Debug - a sine wave program

January 24, 2005 Lecture 3 - By P. Lin 32 Question? Answers