Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An

Similar documents
Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Outline. CSE 1570 Interacting with MATLAB. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Introduction to Engineering gii

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT

PART 1 PROGRAMMING WITH MATHLAB

Matlab Programming Introduction 1 2

Starting Matlab. MATLAB Laboratory 09/09/10 Lecture. Command Window. Drives/Directories. Go to.

Introduction to MATLAB

General Information. There are certain MATLAB features you should be aware of before you begin working with MATLAB.

Basic stuff -- assignments, arithmetic and functions

Introduction to MATLAB

AMS 27L LAB #1 Winter 2009

Welcome to EGR 106 Foundations of Engineering II

Computer Programming ECIV 2303 Chapter 1 Starting with MATLAB Instructor: Dr. Talal Skaik Islamic University of Gaza Faculty of Engineering

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano

EGR 111 Introduction to MATLAB

Chapter 1 Introduction to MATLAB

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing

Introduction to MatLab. Introduction to MatLab K. Craig 1

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain

Dr Richard Greenaway

Computer Programming in MATLAB

Numerical Analysis First Term Dr. Selcuk CANKURT

Lecture 1: Hello, MATLAB!

To start using Matlab, you only need be concerned with the command window for now.

Starting MATLAB To logon onto a Temple workstation at the Tech Center, follow the directions below.

Introduction to Matlab

Introduction to MATLAB

Part #1. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr

MATLAB NOTES. Matlab designed for numerical computing. Strongly oriented towards use of arrays, one and two dimensional.

Introduction to MATLAB. Computational Probability and Statistics CIS 2033 Section 003

Finding, Starting and Using Matlab

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline

LAB 1 General MATLAB Information 1

2.0 MATLAB Fundamentals

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB?

General MATLAB Information 1

Chapter 2. MATLAB Basis

ELEMENTARY MATLAB PROGRAMMING

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

Programming in Mathematics. Mili I. Shah

Lecture 1: What is MATLAB?

MATLAB The first steps. Edited by Péter Vass

Lab 1 - Worksheet Spring 2013

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras

Digital Image Analysis and Processing CPE

MATLAB TUTORIAL WORKSHEET

Matlab as a calculator

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment

Introduction to MATLAB for Numerical Analysis and Mathematical Modeling. Selis Önel, PhD

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

WHAT IS MATLAB?... 1 STARTING MATLAB & USING THE COMMAND LINE... 1 BASIC ARITHMETIC OPERATIONS... 5 ORDER OF OPERATIONS... 7

McTutorial: A MATLAB Tutorial

Introduction to Programming

MATLAB QUICK START TUTORIAL

Introduction to FORTRAN

Part V Appendices c Copyright, Todd Young and Martin Mohlenkamp, Department of Mathematics, Ohio University, 2017

Lecturer: Keyvan Dehmamy

Introduction to Matlab

Matlab Tutorial, CDS

This appendix provides a quick start introduction to MATLAB. You should be

MATLAB: The Basics. Dmitry Adamskiy 9 November 2011

Laboratory 1 Octave Tutorial

Chapter 3. built in functions help feature elementary math functions data analysis functions random number functions computational limits

ANSI C Programming Simple Programs

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks

A General Introduction to Matlab

The Very Basics of the R Interpreter

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.

Introduction to Scientific and Engineering Computing, BIL108E. Karaman

EP375 Computational Physics

Getting to Know Maple

Course Layout. Go to follow instr. Accessible within campus (only for the first download)

Getting started with MATLAB

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group

A GUIDE FOR USING MATLAB IN COMPUTER SCIENCE AND COMPUTER ENGINEERING TABLE OF CONTENTS

Introduction to MATLAB

Variables are used to store data (numbers, letters, etc) in MATLAB. There are a few rules that must be followed when creating variables in MATLAB:

Why use MATLAB? Mathematcal computations. Used a lot for problem solving. Statistical Analysis (e.g., mean, min) Visualisation (1D-3D)

ME 121 MATLAB Lesson 01 Introduction to MATLAB

Introduction to MATLAB

Programming in QBasic

Introduction to MATLAB Practical 1

A/D Converter. Sampling. Figure 1.1: Block Diagram of a DSP System

An Introduction to MATLAB

Green Globs And Graphing Equations

6-1 (Function). (Function) !*+!"#!, Function Description Example. natural logarithm of x (base e) rounds x to smallest integer not less than x

Introduction to Computer Programming with MATLAB Matlab Fundamentals. Selis Önel, PhD

Introduction to MATLAB

Introduction to MATLAB

Python Lists: Example 1: >>> items=["apple", "orange",100,25.5] >>> items[0] 'apple' >>> 3*items[:2]

VARIABLES Storing numbers:

Expressions and Variables

This page intentionally left blank

Chapter 4: Basic C Operators

Introduction to MATLAB Programming

SMS 3515: Scientific Computing Lecture 1: Introduction to Matlab 2014

Transcription:

CSE 170 Interacting with MATLAB Instructor: Aijun An Department of Computer Science and Engineering York University aan@cse.yorku.ca Outline Starting MATLAB MATLAB Windows Using the Command Window Some useful commands Using MATLAB as a calculator Arithmetic operations Order of precedence Elementary math built-in functions 1 http://www.cse.yorku.ca/course/170 Outline (Cont d) Variables The assignment operator Rules for variable names Predefined variables Useful commands for managing variables Starting MATLAB On a campus machine, launch MATLAB through the start menu (clicking on the start button on the bottom left corner of the screen): Start All Programs MATLAB R010a MATLAB R010a At home, launch MATLAB through WebFAS: Log into WebFAS at http://webfas.yorku.ca with your Passport York account Click on Matlab R01a 4 MATLAB Desktop Window MATLAB Windows Desktop window contains four smaller windows Command window Most important window for issuing commands and displaying the results Current Folder window (called Current Directory in some previous versions) Lists the files and sub-folders contained in the current folder The current folder is by default your personal desktop folder (My Documents), or F drive (your FAS home directory) when using WebFAS You can change the current folder (will learn later) 6 1

MATLAB Windows (Cont d) Workspace window Lists the variables currently active Command History window Lists the commands that you have entered in the Command window. You can close and re-open any window Click on x at the top right corner of the window Open by selecting the window name from the Desktop menu Get back to default layout of the Desktop: Desktop Desktop Layout Default 7 MATLAB Windows (Cont d) Three other important windows: Help window 8 Provides help information Can be opened from the Help menu or by typing the doc command in the Command window Editor window (will study later) For writing and editing MATLAB programs and functions. Can be opened from the File menu or by typing edit on command window Figure window (will study later) Opens automatically when graphics commands are executed Contains graphs created by these commands Using the Command Window You can type MATLAB command after >> prompt Practice the following commands date ---- show the current date calendar ---- show a month s calendar (default: current month) 9 clc ---- clear command window pwd ---- show the current folder name ls ---- list the content of current folder up arrow ( ) ---- brings back the last command(s) help (also try help command/function_name) doc (also try doc command/function_name) 10 Type a math expression in the command line and press the Enter key Practice the following math expressions: + 6*8 1/ +6/ (+6)/ +7/+ (+7)/(+) 11 Arithmetic operators: Operation Symbol Example Addition + + Subtraction - - Multiplication * * Division / / Exponentiation ^ ^ (means =1) Practice the following: 6*8-6^ ^- 1 Order of Precedence: Precedence First Second Third Math Operations Parentheses. For nested parentheses, the innermost are executed first. Exponentiation (^) Multiplication (*), division (/) (equal precedence) Fourth Addition (+), subtraction (-) (equal precedence) From left to right for operations with the same precedence What is the result of each of these expressions: *^ (*)^ 6*(8-6)/(*) 6*(8-6)/* ^(-4+1)/((+)*) ^(-4+1)/(+*)

(18/)^-10 18 10 ((18-)/)^-10 18 10 1 6 14 1 7 1 7 6 4 1 9 6 (7/)^*4^*1-6^7/(9^-6) 4.8009 Scientific Notation of Numbers Like in most of scientific calculator, you can express very large or very small values in scientific notation: >> 1.67e7 means 1.67 10 7 1670000 This is same as typing: >> 16.7*100000 or >> 1.67*10^7 16 >> 8e-4 0.008 means 8 10-4 Here e represents times ten raised to the power of Scientific Notation of Numbers You can use scientific notations in math expressions >> 1.67e7 + 1/ 167000 >> 8e-4 * 100 0.800 Built-in Math Functions Expressions in MATLAB can include functions A built-in function is a sub-program provided in MATLAB, which performs a task has a name accepts one or more values as input (called di input arguments) ) returns a value as output Input data Function Output data MATLAB provides many built-in functions, such as sqrt(x), sin(x), cos(x), exp(x), log(x), 17 18

19 An Example of Built-in Functions function name sqrt(x) argument Task: function sqrt(x) computes the square root of x Try the following on the command window: sqrt(9) sqrt(64) sqrt() Elementary Math Built-in Functions 0 Some elementary math functions Function Description Example sqrt(x) Square root of x sqrt(81) nthroot(x,n) nth root of x nthroot(7,) abs(x) Absolute value of x abs(-8) exp(x) Exponential (e x ) exp() log(x) Natural logarithm log(1000) (Base e logarithm) of x log10(x) Base 10 logarithm of x log10(1000) factorial(x) The factorial of x factorial() rem(x,y) The remainder after x is divided by y rem(1,) Exercise 8. 8.*^-sqrt(100) 70.770 100 Exercise 4 ln 00 1. exp(4)-log(00)/1. 1.069 e 1 Variables Examples of Variables A variable is a name (usually made of a letter or several letters and digits) of a piece of memory space used to store a value. The value can be changed from time to time. can be assigned a numerical value by variable_name = a numerical value or a computable expression where = is called assignment operator For example, >> x = can be used in math expressions, in functions and any MATLAB statements and commands. Type the following in the command line: x= which assigns value to variable x. Output from MATLAB: x= Can use x in expressions: y=x^+x+ It first calculates ^++ and then assigns the result to variable y. 4 4

Examples of Variables What is the value in z after executing the following commands? x= y= z=x*y Output: (>> is the prompt; what s after it is the command you input) >> x= >> z=x+y x = z = 1 >> y= y = 6 Examples of Variables What does the following do? x= x=x+ The second line first takes the current value of x, adds to it and assigns the result back to x. Output: (>> is the prompt; what s after it is the command you input) >> x= x = >> x=x+ x = 7 Suppressing the Output You can use ; at the end of a command to suppress the output of the command: x=; which will prevent the output from being displayed. Exercise Define variables x and y as x=. and y=7.8, then calculate: xy ( x y) 7 Thus, x=; y=x^+x+ will only output y value: y= 8 Expression and result: >> x=.; y=7.8; >> x*y/(x-y)^ 6.6144 can put more than one assignment in one line. A comma or semicolon can be used as a separater. Semicolon suppresses the output, while comma does not. Try it. 9 Rules About Variable Names Must begin with a letter Can contain letters, digits and the underscore character. For example, A1, xy, First_name, firstname, cd Cannot contain special characters ($, %, &, @..) MATLAB is case sensitive, i meaning A and a are names of different variables. No space is allowed between characters Use underscore where a space is desired. Avoid using the names of build-in functions (e.g., sqrt, exp, log, sin, cos,...) Avoid using keywords reserved by MATLAB (for, if, else, while,.) 0 Predefined Variables in MATLAB ans hold the value of the last expression if it was not assigned to another variable. pi the number π (.1416) eps a very small number. Equal to -. inf a very big number. Used for infinity. NaN stand for Not-a-Number. Used when MATLAB cannot determine a valid value, such as 0/0. i and j defined as 1 If you assign a value to a pre-defined variable, the predefined value is overwritten.

Useful Commands for Managing Variables who Display a list of the variables currently in the memory. whos Display a list of the variables currently in the memory and their size and other related information. clear Removes all variables from the memory. Exiting MATLAB You can exit MATLAB in one of the following ways: Type one of the following commands in the Command window: exit quit clear x, y, z Removes only variables x, y, and z from the memory. Choose Exit MATLAB from the File menu 1 Click x at the top right corner of the MATLAB Desktop window. Home Exercise Next Class 1 6+ log 6 10 Creating vectors and matrices Location: TEL 07&0 Assign 6 to variable n and calculate the factorial of n. Assign 81 to N and to a. Then calculate log a N 4 6