Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine -------------------------------------------------

Slides:



Advertisements
Similar presentations
Introduction to Applications & Basic Features. What is MATLAB®? MATLAB® /Simulink® is a powerful software tool for: Performing mathematical computations.
Advertisements

Introduction to Programming using Matlab Session 2 P DuffourJan 2008.
Lecture 14 User-defined functions Function: concept, syntax, and examples © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Lecture 4 Structure plan Program design process Program design process Basic elements of code: Basic elements of code: –Input (assignment of variables)
Windows XP Basics OVERVIEW Next.
Lecture 7 Debugging Code & Data Import/Export © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Chapter 8 and 9 Review: Logical Functions and Control Structures Introduction to MATLAB 7 Engineering 161.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
ES 100: Introduction to Engineering Use of the Computer 1.Log in using your Novell password. If you do not know your password, immediately (now!) see Al.
Lecture 3 Creating M-files Programming tools: Input/output(assign/graph-&-display) Repetition (for) Decision (if) © 2007 Daniel Valentine. All rights reserved.
Lecture 12 Another loop for repetition The while loop construct © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = B = >> X = A\B X =
Microsoft Access 2007 Microsoft Access 2007 Introduction to Database Programs.
Exploring Microsoft Excel 2002 Chapter 8 Chapter 8 Automating Repetitive Tasks: Macros and Visual Basic for Applications By Robert T. Grauer Maryann Barber.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
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.
Digital Image Processing Lecture3: Introduction to MATLAB.
Lecture 15 Practice & exploration Subfunctions: Functions within functions “Guessing Game”: A hands-on exercise in evolutionary design © 2007 Daniel Valentine.
(c) Bob McKillop, 2006Tutorial #1 T1-1 Tutorial #1 - your first compiled code  the learning objectives for this tutorial are very modest q compile and.
A First Program Using C#
BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists.
THE MATLAB ENVIRONMENT VARIABLES BASIC COMMANDS HELP HP 100 – MATLAB Wednesday, 8/27/2014
1 Chapter 1 MATLAB Primer This introductory chapter is relatively short and has as its main objective the introduction of MATLAB ® to the reader. This.
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.
Ch 101 Chapter 10 Introduction to Batch Files. Ch 102 Overview A batch file is a text file that contains an ordered series of commands.
Shell Scripting Introduction. Agenda What is Shell Scripting? Why use Shell Scripting? Writing and Running a Shell Script Basic Commands -ECHO - REM.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Lesson 1 Introduction.
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.
Chapter 1: Getting Started with MATLAB MATLAB for Scientist and Engineers Using Symbolic Toolbox.
Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
Introduction to Engineering MATLAB – 2 Introduction to MATLAB - 2 Agenda Defining Variables MATLAB Windows.
CMPS 1371 Introduction to Computing for Engineers MatLab.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Winter Semester 2014/2015 College of Engineering.
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.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Introduction to MATLAB 7 MATLAB Programming for Engineer Hassan Migdadi Spring 2013.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
ENG 1181 First-Year Engineering Program College of Engineering Engineering Education Innovation Center First-Year Engineering Program MAT - Introduction.
Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2012.
Introduction to MATLAB Section2, statistics course Third year biomedical dept. Dina El Kholy, Ahmed Dalal.
1 Lecture 4 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
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.
Functions Commands Programming Steps Examples Printing Homework Hints.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Using Macros Lesson.
Exploring Excel Chapter 7 Automating Repetitive Tasks: Macros and
Release Numbers MATLAB is updated regularly
Matlab Training Session 4: Control, Flow and Functions
Lecture 1: Introduction
Exploring Microsoft Excel
Digital Image Processing
Lecture 4 Structure plan
Matlab.
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Experiment No. (1) - an introduction to MATLAB
Lecture 0 Preface Essential MATLAB for Engineers and Scientists
Running a Java Program using Blue Jay.
Presentation transcript:

Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine Lectures by Daniel T. Valentine © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.

Objectives of course Learn how to examine, explore and evaluate MATLAB. Learn how to examine, explore and evaluate MATLAB. Learn how to do technical computing with MATLAB. Learn how to do technical computing with MATLAB. Learn how to design programs to solve technical problems via structure plan (i.e., a design methodology). Learn how to design programs to solve technical problems via structure plan (i.e., a design methodology). Learn to formulate algorithms for the steps of the structure plan. Learn to formulate algorithms for the steps of the structure plan. Learn how to translate the steps into computer programs to solve engineering and scientific problems. Learn how to translate the steps into computer programs to solve engineering and scientific problems.

Objective of this lecture Provide an overview of some of the features of MATLAB as a way to begin your: Provide an overview of some of the features of MATLAB as a way to begin your: –Evaluation of this new technical computing tool. –Training in the art of computer programming. –Learning to use MATLAB as a notepad for mathematical computations that arise in engineering and science courses.

MATLAB desktop Command Window Command History Window Workspace Window Current Directory Window Start Button

Command Window The Command Window on the right is the main panel where you interact with MATLAB. The Command Window on the right is the main panel where you interact with MATLAB. You key (or type) and commands after the prompt >>; MATLAB executes the commands and displays results (if requested). You key (or type) and commands after the prompt >>; MATLAB executes the commands and displays results (if requested). Some commonly used tools and commands: Some commonly used tools and commands: –  (up arrow) returns last command input, can be repeated –clc – clears the screen –whos – shows list of variables –clear – clears variables

Evaluation of MATLAB HANDS-ON with MATLAB HANDS-ON with MATLAB –Type >> 2+3 >> 2+3 into the Command Window >> clc >> clc >> whos >> whos Throughout the lecture, yellow text indicates what you should type into MATLAB.

Command History Window The Command History Window logs all of the commands you enter in MATLAB. The Command History Window logs all of the commands you enter in MATLAB. It should have logged 2+3. It should have logged 2+3. Use the Command History Window to reenter 2+3 in the command window (use copy-and- paste or double click on 2+3). This is useful to retrieve past commands. This is useful to retrieve past commands. Use “Shift” key to select multiple lines. Use “Shift” key to select multiple lines.

Arithmetic with MATLAB Let us explore by doing exercises: Let us explore by doing exercises: >> 3–2 >> 3–2 >> 3*2 >> 3*2 >> 3/2 >> 3/2 >> 3\2 >> 3\2 >> 3^2 >> 3^2 >> 2/0 >> 2/0 >> 0/2 >> 0/2 >> 3*Inf >> 3*Inf

Algebraic-numeric computations Let us explore by doing exercises: Let us explore by doing exercises: >> a = 3 >> a = 3 >> b = 2 >> b = 2 >> a – b >> a – b >> a / b >> a / b >> a^2 >> a^2 >> c = a * b >> c = a * b >> d = c^(b+1) >> d = c^(b+1) >> who

Hiding Output Let us explore by doing exercises: Let us explore by doing exercises: >> clear; clc >> clear; clc >> whos >> whos >> a = 3; >> a = 3; >> b = 2; >> b = 2; >> c = a * b; >> c = a * b; >> d = c^(b+1); >> d = c^(b+1); >> who >> who >> % a, b, c, d are in workspace >> % a, b, c, d are in workspace >> a, b, c, d >> a, b, c, d

Plot y versus x Introduction to plotting & displaying data: Introduction to plotting & displaying data: >> clear; clc >> clear; clc >> x = 0:0.1:1; >> x = 0:0.1:1; >> y = x.^2; >> y = x.^2; >> whos >> whos >> plot(x,y,x,y,’o’) >> plot(x,y,x,y,’o’) >> disp(' '),disp(' x y.....'),disp([x‘ y']) >> disp(' '),disp(' x y.....'),disp([x‘ y']) >> x >> x >> y >> y >> % x and y are 1-by-11 arrays of numbers!

Write a Simple Program Consider computing the volume of a cone: Consider computing the volume of a cone: Volume = (pi.*r.^2.*h)./3 radius = 6 inches height = 12 inches In the command window key in: In the command window key in: >> clear; clc >> clear; clc >> r = 6 >> r = 6 >> h = 12 >> h = 12 >> v = (pi.*r.^2.*h)./3 >> v = (pi.*r.^2.*h)./3 >> whos >> whos

Editor & M-Files An M-file in MATLAB is analogous to a txt- file in Microsoft Notepad. An M-file in MATLAB is analogous to a txt- file in Microsoft Notepad. An M-file is created in MATLAB text editor. An M-file is created in MATLAB text editor. M-files: M-files: –You can save your programs (i.e., list of executable commands) as M-files. –You can reopen and modify your program. –They are useful for “debugging” (correcting errors) as you develop your programs (your technical computing tools).

Comments in programs Every time you write a program to be saved, it is helpful for you to comment (i.e., describe) it well. Every time you write a program to be saved, it is helpful for you to comment (i.e., describe) it well. To insert a comment on a line in the editor or in the Command Window, use the comment operator %, then type your comment. To insert a comment on a line in the editor or in the Command Window, use the comment operator %, then type your comment. MATLAB: MATLAB: –will not run lines that begin with the comment operator (in the editor comments appear in green). Comments Comments –Comments allow you (and others) to more easily understand your program. –When your lines of code are easy to understand, your code will be easier to use later.

Art of well-written code A well-written program is like literature; it contains comments explaining: A well-written program is like literature; it contains comments explaining: –what your program requires as input. –what the variables in the program represent. –what your program computes and displays. It is useful for you to add a set of header comments that include the name of the program, your name (as the programmer), and the date the program was created or modified. It is useful for you to add a set of header comments that include the name of the program, your name (as the programmer), and the date the program was created or modified.

Saving code in an M-File Open the editor by: Open the editor by: –Entering the command edit in the command window. –Or click the white-sheet-of-paper icon in the upper left hand corner directly below file. Now enter the lines of code to find the volume of a cone: Now enter the lines of code to find the volume of a cone: rr = 4 h = 12 v = (pi.*r.^2.*h)./3 REMARK: If you save it, add header comments and comments explaining what the program does. After you have typed in the code, save it as cone.m. After you have typed in the code, save it as cone.m.

This is cone.m in the editor % % Tool to compute the volume of a cone. % A simple sample for a first lecture. % B.H.& Daniel January 2007 % rr = 4; % radius of the cone h = 12; % height of the cone v = (pi.*r.^2.*h)./3 % Volume of the cone

Execute an M-file as a Command Now execute (or run) the program by pushing F5, or by typing on the command line Now execute (or run) the program by pushing F5, or by typing on the command line >> cone >> cone – or by clicking the run button. (Note that the run button looks like a page with a down arrow to its left. It can be found below help on the toolbar of the edit window.) If you entered the code as written on the previous slide you will get an error! If you entered the code as written on the previous slide you will get an error! What went wrong? What went wrong? Repair your program (Change rr = 4 to r = 4.), save it, and run it again. Repair your program (Change rr = 4 to r = 4.), save it, and run it again. Now change the height to 24, save and run your program again. Now change the height to 24, save and run your program again.

Summary MATLAB can be used like a hand calculator to do arithmetic. MATLAB can be used like a hand calculator to do arithmetic. You can define (or assign) variables with numbers and expressions to do calculations as illustrated by the volume-of-cone example. You can define (or assign) variables with numbers and expressions to do calculations as illustrated by the volume-of-cone example. The advantage of saving programs as M-files is that you open it, make changes and/or execute it again without having to type it all over again. The advantage of saving programs as M-files is that you open it, make changes and/or execute it again without having to type it all over again. This concludes our overview of MATLAB and a taste of things to come! This concludes our overview of MATLAB and a taste of things to come!