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.

Slides:



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

Input and Output ENGR 1181 MATLAB 5. Input and Output In The Real World Script files (which provide outputs given inputs) are important tools in MATLAB.
Welcome to EGR 106 Foundations of Engineering II Course information Today’s specific topics: – Computation and algorithms – M ATLAB Basics Demonstrations.
Lecture 6 MATLAB functions Basics of Built-in Functions, Help Feature, Elementary Functions (e.g., Polynomials, Trigonometric Functions), Data Analysis,
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.
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.
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
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.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (2): MATLAB Environment (Chapter 1)
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.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Functions 1 ENGR 1181 MATLAB 14.
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 Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
EECE 360/460 Matlab Tutorial Jan Outline What is Matlab? What is Matlab? Matlab Interface Matlab Interface Basic Syntax Basic Syntax Plotting Graphs.
Release Numbers MATLAB is updated regularly The Mathworks packages their software in groups, called releases, New releases are issued twice a year in the.
For Loops 1 ENGR 1181 MATLAB 8. For Loops and Looped Programming in Real Life Looping within programs has long been a useful tool for completing mundane.
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.
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.
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
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
MATLAB Technical Computing Environment. MATLAB Matlab is an interactive computing environment that enables numerical computation and data visualization.
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.
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 &
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
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.
Array Creation ENGR 1181 MATLAB 2. Civil engineers store seismic data in arrays to analyze plate tectonics as well as fault patterns. These sets of data.
ENG 1181 First-Year Engineering Program College of Engineering Engineering Education Innovation Center First-Year Engineering Program MAT - Introduction.
Array Operations ENGR 1181 MATLAB 4.
Fundamentals of Programming 20-ENFD-112 Sections 001 to 007 Instructor: Prof. Dieter Schmidt Lecture: Monday, Wednesday 3:00-3:50 Web page
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 for Engineers Matlab Environment Chapter 2.
Array Accessing and Strings ENGR 1187 MATLAB 3. Today's Topics  Array Addressing (indexing)  Vector Addressing (indexing)  Matrix Addressing (indexing)
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.
Basic operations in Matlab EE 201.  Achieve Comprehension LOL of Matlab basic operations. Class Learning Objectives 2.
Introduction to MATLAB
ECE 1304 Introduction to Electrical and Computer Engineering
Arithmetic Operations
ECE 1304 Introduction to Electrical and Computer Engineering
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
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.
Introduction to MATLAB
MatLab Program Used to Calculate Interactive
Introduction to Matlab
Presentation transcript:

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

Today's Learning Objectives  After today’s class, students will be able to: Demonstrate proper usage of basic MATLAB features (e.g., the Command Window, script files, other default windows, arithmetic operations, assigning variables and names, built-in functions, help command). Identify need to translate mathematical notation into proper MATLAB syntax.

Today's Topics  Intro to the MATLAB interface  Variables: naming rules & calculations  Functions  Script files and other commands

Opening MATLAB  Students, please open MATLAB now.  CLICK on the shortcut icon → Alternatively, select… start/All programs/MATLAB  The following prompt should appear in the command window after a lengthy initialization process: >>

MATLAB Display  Ribbon Useful operations  Current Directory List of files  Workspace Defined variable values  Command history Displays what has been typed Command prompt Command Window

MATLAB’s Working Directory  Current working directory 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  Browse icon available

Order of Precedence - important  Higher-precedence operations are executed before lower-precedence operations Similar to Excel or programmable calculators  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

Order of Precedence  Example: Find the average of two numbers: 7 and 8 >> 7+8/2>> (7+8)/2

Order of Precedence  Example: Find the average of two numbers: 7 and 8 >> 7+8/2>> (7+8)/2ans = Incorrect result

Order of Precedence  Example: Add the cube root of 27 to the 5 th root of 32 >>27^1/3 + 32^0.2

Order of Precedence  Example: Add the cube root of 27 to the 5 th root of 32 >>27^1/3 + 32^0.2 ans = 11 Undesired result…press the UP arrow key, then add the parenthesis around the “1/3” >>27^(1/3) + 32^0.2 ans = 5

Variable Definition – Key Points >> x = 5 x = 5 >> x = x + 5 x = 10 This statement does not make mathematical sense. However in programming language, it changes the value of “x” to a new value based on its previously defined value.

Calculations with Variables  Variables defined previously can be used to do calculations  Define: a = 8, my_var = 12 >> a + my_var ans = 20 >> a*my_var^2 ans = 1152

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, it distinguishes between uppercase and lowercase letters  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)

MATLAB Built-in Math Functions  Pre-defined in MATLAB ready for use 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 standard trigonmetric functions, the units for angles are radians, e.g. sin(x), cos(x), asin(x), acos(x), tan(x), cot(x)  There are equivalent functions for degrees, e.g. sind(x), cosd(x), asind(x), acosd(x), tand(x), cotd(x)

MATLAB Built-in Math Functions  Ex: To calculate sin(/2) >>sin(pi/2)  is defined as “pi” ans = 1  Ex: To calculate e 2 >>e^2>> exp(2) ??? Undefined ans = function or variable ‘e’7.3891

MATLAB Built-in Math Functions  Ex: To calculate sin(2x) where x = /4 >> x = pi/4 x = >> sin(2*x) ans = 1

MATLAB Built-in Math Functions

Saving a Script File  Script files must be saved after completion  In our class use Save As to your Z:\ or USB drive This should be the same as the working directory you specified upon starting MATLAB SAVE YOUR WORK AS YOU GO!

Saving a Script File Allowed:Not Allowed: Prob1a.mProb 1a.m (blank space) Prob_1a.m1aProb.m (can’t start with numeric) Prob-1a.m (no special characters)  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)

Useful Programming Commands  To clear the command window, use “clc” >> clc  To clear all variables previously defined from memory, use “clear”  Ex: define x = 5 >> x = 5>> clear x = >> x 5??? Undefined function or variable “x”

 To send a text message to the command window or display contents of a variable, use “disp(…)” >> disp(‘Brutus Buckeye’) NOTE: single quotes Brutus Buckeye >> x = 5>> disp(x) No quotes for variable x = 5 5 Useful Programming Commands

 To suppress the command window output, use a semicolon after the statement “;” >> x = 5>> x = 6; x =The value of x is changed 5but not displayed >> x>> disp(x) x =x =6 Useful Programming Commands

Script File Example

 Steps for creating script 1.Create a script file and name it Pyth.m 2.Clear the command window 3.Clear all variables from memory 4.Display your name and seat number 5.Declare height of triangle as 3 units 6.Declare base of triangle as 4 units 7.Find the hypotenuse of the triangle

Script File Example  Print of the script file.  Print of the output (command window).

Homework Example  Script file to print  Command window to print clc disp(‘Student, Joe’) disp(‘ENGR 1181, Seat 99’) disp(‘MAT – Introduction’) disp(‘Problem 4’) Prob4a = cos(5*pi … … Student, Joe ENGR 1181, Seat 99 MAT – Introduction Problem 4 prob4a = …

Important Takeaways  Programming is a useful and powerful tool for problem solving in any engineering discipline  MATLAB is a tool to solve these types of problems  Basics of MATLAB interface  Variable naming and rules  Basic math operations and calculations  Script files and other useful commands

Preview of Next Class  Array Creation Difference between scalar and vector 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?  Review today’s Quiz #01  Open the in-class activity from the EEIC website and we will go through it together.  Then, 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.