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.

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 MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
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 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 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.
Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine
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.
THE MATLAB ENVIRONMENT VARIABLES BASIC COMMANDS HELP HP 100 – MATLAB Wednesday, 8/27/2014
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
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.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
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.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB is a powerful program for numerical computations, plotting and programming.
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 Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
Release Numbers MATLAB is updated regularly The Mathworks packages their software in groups, called releases, New releases are issued twice a year in the.
Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 1.
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
Chapter 1: Getting Started with MATLAB MATLAB for Scientist and Engineers Using Symbolic Toolbox.
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.
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.
Introduction to Programming with RAPTOR
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Winter Semester 2014/2015 College of Engineering.
Scientific Computing Introduction to Matlab Programming.
Introduction to MATLAB ENGR 1181 MATLAB 1. Opening MATLAB  Students, please open MATLAB now.  CLICK on the shortcut icon → Alternatively, select… start/All.
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”
Matlab. Textbooks Required:, by Palm (3 rd edition) Required: Introduction to MATLAB for Engineers, by Palm (3 rd edition)
1 Lecture 1 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
EGR 115 Introduction to Computing for Engineers Introduction to MATLAB Friday 29 August 2014 EGR 115 Introduction to Computing for Engineers.
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.
Array Creation ENGR 1187 MATLAB 2. Today’s Topics  Arrays: What are they?  Vectors  Matrices  Creating Arrays.
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.
MATLAB Lecture 1 염익준. Introduction MATLAB (MATrix LABoratory) a special purpose computer program optimized to perform engineering and scientific calculations.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
Introduction to MATLAB
ECE 1304 Introduction to Electrical and Computer Engineering
Arithmetic Operations
ECE 1304 Introduction to Electrical and Computer Engineering
L2. Basics Variables and Expressions Assignment Statements
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Lecture 1: Introduction
Matlab.
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Experiment No. (1) - an introduction to MATLAB
Using Script Files and Managing Data
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 Basics Tutorial
Introduction to MATLAB
MatLab Program Used to Calculate Interactive
Introduction to Matlab
Chapter 2 MATLAB Environment
Presentation transcript:

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 is a program used for solving problems through numerical computation, plotting and logical programming. Devices such as robots are controlled by programs that act as a set of instructions for completing a task.

Today's Topics  Introduction to the MATLAB interface  Arithmetic Operations: Order of precedence  Defining Variables  Built-In Functions  Script Files  In Class Example

Today's Topics  Introduction to the MATLAB interface  Arithmetic Operations: Order of precedence  Defining Variables  Built-In Functions  Script Files  In Class Example

Opening MATLAB  Open MATLAB now.  CLICK on the shortcut icon → Alternatively, start/All programs/MATLAB  The prompt “ >> “ should appear in the command window after initialization.

MATLAB Display [1] Current Folder [2] Work Space [3] Command History [4] Command Window

The Current Folder: MATLAB’s Working Directory  Current folder is where files are saved and run from  When you first start MATLAB, it is a good practice to change the working directory to your Z: drive or USB device using the browse icon.

Today's Topics  Introduction to the MATLAB interface  Arithmetic Operations: Order of precedence  Defining Variables  Built-In Functions  Script Files  In Class Example

Arithmetic Operations: Order of Precedence  Higher-precedence operations are executed before lower- precedence operations  Two operations having the same precedence are executed from left to right. PRECEDENCE OPERATION FirstParentheses (innermost pair first) SecondExponentiation ThirdMultiplication and division FourthAddition and subtraction

 Example: Find the average of two numbers: 7 and 8 >> 7+8/2>> (7+8)/2  Which command input is correct, A or B? ans = 11 ans = 7.5 B B is the correct input (ans = 7.5). Arithmetic Operations: Order of Precedence A B

 Example: Add the cube root of 27 to the 5 th root of 32 >> 27^1/3 + 32^0.2 >> 27^(1/3) + 32^0.2  Which command input is correct, A or B? ans = 11 ans = 5 B B is the correct input (ans = 5). Arithmetic Operations: Order of Precedence A B

Today's Topics  Introduction to the MATLAB interface  Arithmetic Operations: Order of precedence  Defining Variables  Built-In Functions  Script Files  In Class Example

Defining Variables  In MATLAB we can assign data to variables so they can be stored in memory.  For example, enter the following in the command window & hit enter: >> x = 5  Now look at your work space

Defining Variables  Now this variable can be used in arithmetic operations.  For example, enter the following in the command window & hit enter: >> x + 5 (you should get 10!)  Now say we want to add 15 to x and make x the new value. This is reassigning the variable x. >> x = x + 15 Now check your workspace, what’s the value of x?

Rules in Naming Variables  Variable names cannot exceed 63 characters  Names must begin with a letter  May contain letters, digits, and the underscore character No spaces are allowed  MATLAB is case sensitive  Avoid naming variables with currently defined MATLAB functions Ex: exp, sin, cos, sqrt, length, mean, max, min etc.

Variable Name Examples  Allowed My_name MyName Myname32  Not allowed 1Name (starts with numeral) My Name (no spaces allowed) My-Name (no special characters allowed)

Calculations with multiple variables  Define the following two variables: >> var1 = 5 >> var2 = 20  Now we can use these two variables to perform arithmetic operations and create a new variable in the process. >> var3 = var2/var1 (you should get 4!)  Now check your workspace and you should see these variables.

Today's Topics  Introduction to the MATLAB interface  Arithmetic Operations: Order of precedence  Defining Variables  Built-In Functions  Script Files  In Class Example

Built-In Functions  Examples of Pre-defined in MATLAB exp(x) – exponential (e x ) log(x) – natural logarithm (log e (x)) log10(x)– base 10 logarithm (log 10 (x)) sqrt(x)– square root (√x) abs(x) – absolute value (|x|)  For trigonmetric functions, x is entered in radians sin(x), cos(x), asin(x), acos(x), tan(x), cot(x)  To enter x in degrees… sind(x) where x is in degrees

Built-In Functions

 Let’s combine what we have learned so far: Example 1: Calculate sin(2x) where x = /4 Solution  >> x = pi/4  >> sin(2*x)  ans = 1

Built-In Functions

Command Window Functions  To clear the command window, use “clc”  To clear all variables defined in our workspace, use “clear”

Today's Topics  Introduction to the MATLAB interface  Arithmetic Operations: Order of precedence  Defining Variables  Built-In Functions  Script Files  In Class Example

Script Files  A MATLAB script file (.m extension) is a program file created by you the user that executes a series of MATLAB commands (i.e., basic arithmetic).  A new script file can be opened by selecting the new script icon under the Home tab.

Script Files  Script files should be saved periodically as you are programming.  In this class save to your Z-drive or a USB drive. Remember, wherever you save your file should be the same as the working directory you are working in. SAVE YOUR WORK AS YOU GO!

Saving a Script File  The name of the script file is governed by the following rules: No spaces are allowed The name cannot start with a numeric No special characters are allowed (except underscore) Allowed:Not Allowed: Prob1a.mProb 1a.m (blank space) Prob_1a.m1aProb.m (can’t start with numeric) Prob-1a.m (no special characters)

Useful Commands in Script Files  To suppress command window output, use a semicolon after the statement “;” For example: x = 5;  To send a text message to the command window or display contents of a variable, use “disp(…)” Example 1: disp( ‘Hello World’ )  Note: The text in this command is referred to as a string. Strings must have single quotes at both ends of the string. Example 2: disp(x)  Displays the values stored in x

Script File Header  All homework and in class activities done must include a header as shown below. Example is provided on the course website.  NOTE: NO TEXT GOES PAST THE VERTICAL LINE

Today's Topics  Introduction to the MATLAB interface  Arithmetic Operations: Order of precedence  Defining Variables  Built-In Functions  Script Files  In Class Example

In Class Example

 Steps for creating script (similar to homework format) 1.Create a script file and name it Pyth.m 2.Create script file header (programmer info) 3.Create the body of the program a)Assign the height of the triangle to a variable b)Assign the base of triangle to a variable c)Compute the hypotenuse of the triangle

In Class Example  Solution

Publishing you work  When submitting your work use the publishing tool in MATLAB to create a PDF of your work. Select:  Publish tab  Publish Drop Down Menu  Edit Publishing Options…

Publishing you work  In the Edit Configurations window under Output Settings: Select the box to the right of Output file format  Select PDF and close.

Publishing you work  Not select the publish button and MATLAB will run your script file and create a PDF of your script file and the output

Preview of Next Class  Array Creation Difference between scalars and vectors How to create a row/column vector in MATLAB Examples of how to set constant spacing in vectors Special commands and matrix examples

What’s Next?  Submit the in-class activity to todays dropbox  Review today’s Quiz #01  Start working on MAT-01 homework.  Prepare for next class by reading about array creation in MATLAB - array creation is a useful way to store data to be analyzed or plotted.