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.

Slides:



Advertisements
Similar presentations
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Advertisements

Introduction to FX Equation 4. The Basic Idea FX Equation is DIFFERENT. Most equation editors use a point and click interface that has you searching for.
Introduction to C Programming
Welcome to EGR 106 Foundations of Engineering II Course information Today’s specific topics: – Computation and algorithms – M ATLAB Basics Demonstrations.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Introduction to MATLAB 7 for Engineers
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 C Programming
Pseudocode.
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.
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.
MATLAB Fundamentals.
Chapter 4 MATLAB Programming Combining Loops and Logic Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine
Visual Basic Chapter 1 Mr. Wangler.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
Simple Programs from Chapter 2 Putting the Building Blocks All Together (corresponds with Chapter 2)
Lecture 4 MATLAB Windows Arithmetic Operators Maintenance Functions
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.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
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.
Introduction to MATLAB ENGR 1181 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
MATLAB Basics. The following screen will appear when you start up Matlab. All of the commands that will be discussed should be typed at the >> prompt.
Chapter 1: Getting Started with MATLAB MATLAB for Scientist and Engineers Using Symbolic Toolbox.
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.
MATLAB Harri Saarnisaari, Part of Simulations and Tools for Telecommunication Course.
Week 1 Algorithmization and Programming Languages.
Introduction to Programming with RAPTOR
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
Scientific Computing Introduction to Matlab Programming.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
1 Week 1: Variables, assignment, expressions READING: 1.2 – 1.4.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Getting Started with MATLAB (part2) 1. Basic Data manipulation 2. Basic Data Understanding 1. The Binary System 2. The ASCII Table 3. Creating Good Variables.
1 Lecture 1 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.
ENG 1181 First-Year Engineering Program College of Engineering Engineering Education Innovation Center First-Year Engineering Program MAT - Introduction.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Today we will learn MATLAB Click Start  All programm  Class Software  Matlab This command window will be seen with a prompt sign >> Any command can.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Matlab for Engineers Matlab Environment Chapter 2.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Structured Computer Programming EE 201 Introduction to MATLAB 7 for Engineers بسم الله الرحمن الرحيم King Abdulaziz University College of Engineering Dept.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
ECE 1304 Introduction to Electrical and Computer Engineering
Chapter 6 JavaScript: Introduction to Scripting
Variables, Expressions, and IO
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Lecture 1: Introduction
Experiment No. (1) - an introduction to MATLAB
MATLAB Introduction MATLAB can be thought of as a powerful graphing calculator but with a lot more buttons! It is also a programming language, commands.
MatLab Program Used to Calculate Interactive
Introduction to Matlab
Presentation transcript:

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 early introduction has the purpose of familiarizing the reader with the basic operations of MATLAB so that the program may be used throughout the book to support the mathematical analysis.

2 Desktop Layout The screen shown on the next slide is based on Version7, Release 14. The Student Version of MATLAB comes with the Symbolic Mathematics Toolbox and the program Simulink. All examples in the text should work with the Student Version

3

4 Prompt MATLAB automatically inserts the prompt >> at the beginning of each line in the Command Window of the Professional Version. The corresponding prompt for the Student Version is EDU>>. We will assume the shorter prompt of the Professional Version throughout the text and the presence of the prompt on a line will alert the reader to the fact that a MATLAB command and possible results will follow.

5 Command Window The Command Window may be used on an interactive basis by simply typing in the commands after >> for the Professional Version or after EDU>> for the Student Version on a line-by-line basis. Depress Enter on the keyboard after each line is entered, and any results generated by the command will immediately appear on the screen unless the addition of a semicolon has suppressed the display or unless the command is part of a sequence.

6 Notational Conventions In the MATLAB examples, we will usually display the results exactly as they appear on the screen. This means that the type style will be different from the standard mathematical style in the remainder of the book, but the symbols should be perfectly clear. Standard mathematical notation includes italicized symbols with subscripts and/or superscripts but MATLAB notation will be non-italicized without subscripts or superscripts.

7 Command Window versus M-files The Command Window will allow you to work in a manner similar to that of a calculator. You can enter a command and see the numerical results immediately. The important thing is that it is interactive. This is in contrast to the writing of M-files, which is performed in a different window. An M-file is a form of computer program.

8 Clear Commands Clearing the screen: >> clc Clearing all variables: >> clear Clearing a variable x: >> clear x

9 Spacing Blank spaces between distinct sections of a command line may be used to avoid a “crowded” appearance provided that they don't disrupt a particular command function or number. Thus, x=5, x = 5, and x = 5 are all acceptable. However, if the number is 51, you will get an error message if you try to put a space between the 5 and the 1. Likewise a variable x1 cannot be expressed as x 1.

10 Basic Arithmetic Operations In many of the slides that follow, basic arithmetic operations will be employed using simple numbers to illustrate the manner in which the command window can be used in much the same way as a calculator. To save space on the slides, many of the blank lines that appear on the computer screen will be eliminated.

11 Entering Numbers >> 5 ans = 5 >> x = 5 x = 5 >> y = 3 y = 3

12 Addition and Subtraction >> z1 = z1 = 8 >> z1 = x + y z1 = 8 >> z2 = y - x z2 = -2

13 Checking on the Variables >> whos Name Size Bytes Class x 1x1 8 double array y 1x1 8 double array z1 1x1 8 double array z2 1x1 8 double array This information may also be found in the Current Directory window.

14 Multiplication Multiplication is performed by placing an asterisk (*) between the numbers. >> z3 = 5*3 z3 = 15 >> z3 = x*y z3 = 15

Division Division of x by y is performed as follows: >> z4 = x/y z4 = An alternate form is as follows: >> z4 = y\x z4 =

16 Exponentiation Exponentiation is performed by using the symbol (^). >> z5 = x^2 z5 = 25

17 Suppressing the Listing of Results If it is desired to perform a computation and not show it on the screen, the command should be followed by a semicolon (;). For example, >>z6 = y^x; The value is in memory and may be seen by entering the variable name. >> z6 z6 = 243

18 Entering in Exponential Form A microwave frequency of 15 GHz (1 GHz = 10 9 Hz) may be entered as >> f = 15e9 f = e+010 Boltzmann’s constant k = 1.38x J/K may be entered as >> k = 1.38e-23 k = e-023

19 Square Root >> z7 = sqrt(x) z7 =

20 Hierarchy Without parentheses, the normal hierarchy of arithmetic operations is exponentiation, multiplication, division, addition, and subtraction. Parentheses may be used to change the order. When in doubt, it is prudent to add parentheses to ensure that the order is performed properly. The process of placing parentheses within parentheses is called nesting.

21 Consider the algorithm shown below. 1. Add 3 to x. 2. Square the result of step Multiply the result of step 2 by Add 8 to the result of step Take the square root of step 4 and the value obtained is y.

22 The algorithm may be implemented by MATLAB on a step-by-step basis. >> u1 = 3 + x ; >> u2 = u1^2 ; >> u3 = 6*u2 ; >> u4 = 8+u3 ; >> y = sqrt(u4) y =

23 The algorithm may be implemented in one step using nesting. >> y = sqrt(8+(6*((3+x)^2))) y =

24 Some MATLAB Constants >> pi ans = >> eps ans = e-016 >> sqrt(-1) ans = i The next slide shows 4 ways to enter an imaginary number.

25 >> 5i ans = i >> 5j ans = i >> i*5 ans = i >> j*5 ans = i

26 Division by Zero Divison by zero will either yield Inf (“infinity”) or NaN (“not a number”) depending on the form. As examples, if the command 1/0 is entered, the result is Inf, and if the command 0/0 is entered, the result is NaN.

27 Programming with M-Files A computational procedure may need to be repeated for more than one set of input data and/or the code consists of a relatively long list of commands. In this case, it is usually more convenient to develop an M-file, which may be saved and used as often as desired. An M-file (or M-file script) is a MATLAB-based computer program for performing a particular analysis.

28 Programming with M-Files (Continuation) Any of the commands that may be applied in the Command Window may be combined into an M-file program. Instructions for accepting input data for different cases may be added to the programs. To use the MATLAB editor, left- click on File and left-click on New. After preparing the file, it should be saved with the extension.m. Details are provided in the text.