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

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

Introduction to Engineering gii

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

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

Computer Programming ECIV 2303 Chapter 6 Programming in MATLAB Instructor: Dr. Talal Skaik Islamic University of Gaza Faculty of Engineering

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

Introduction to MATLAB

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT

1 Overview of the standard Matlab syntax

Chapter 7: Programming in MATLAB

Introduction to MatLab. Introduction to MatLab K. Craig 1

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing

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

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

Desktop Command window

An Introduction to MATLAB

1 Introduction to Matlab

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

Chapter 1: An Overview of MATLAB

EGR 111 Introduction to MATLAB

PART 1 PROGRAMMING WITH MATHLAB

Matlab Programming Introduction 1 2

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

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

2.0 MATLAB Fundamentals

Dr Richard Greenaway

User Defined Functions

MATLAB Introduction to MATLAB Programming

MATLAB Project: Getting Started with MATLAB

Computer Programming in MATLAB

OUTLINE. Number system. Creating MATLAB variables Overwriting variable Error messages Making corrections Entering multiple statements per line

Lab 1 Intro to MATLAB and FreeMat

Introduction to Scientific and Engineering Computing, BIL108E. Karaman

MATLAB Project: Getting Started with MATLAB

INTRODUCTION TO NUMERICAL ANALYSIS

MATLAB The first steps. Edited by Péter Vass

General MATLAB Information 1

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

Python Programming Exercises 1

The Very Basics of the R Interpreter

LAB 1 General MATLAB Information 1

Computer Project: Getting Started with MATLAB

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

Spreadsheet EXCEL. Popular Programs. Applications. Microsoft Excel. What is a Spreadsheet composed of?

Programming in Mathematics. Mili I. Shah

MATLAB Introduction To Engineering for ECE Topics Covered: 1. Creating Script Files (.m files) 2. Using the Real Time Debugger

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

Finding, Starting and Using Matlab

Introduction to Computers. Laboratory Manual. Experiment #3. Elementary Programming, II

Math 98 - Introduction to MATLAB Programming. Fall Lecture 1

Using Basic Formulas 4

T H E I N T E R A C T I V E S H E L L

Matlab Introduction. Scalar Variables and Arithmetic Operators

An Introduction to MATLAB See Chapter 1 of Gilat

MAT 275 Laboratory 1 Introduction to MATLAB

MATLAB - Lecture # 4

FSA Geometry EOC Practice Test Guide

Fundamentals: Expressions and Assignment

ISETL Getting Started Guide

An Introduction to MATLAB

CSCE 120: Learning To Code

ELEMENTARY MATLAB PROGRAMMING

Introduction to MATLAB

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

Objective- Students will be able to use the Order of Operations to evaluate algebraic expressions. Evaluating Algebraic Expressions

Learning the Language - V

McTutorial: A MATLAB Tutorial

APPM 2460 Matlab Basics

MATH 2221A Mathematics Laboratory II

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

Fitting data with Matlab

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

This page intentionally left blank

Introduction to MATLAB

9. Elementary Algebraic and Transcendental Scalar Functions

Introduction to MATLAB

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

Grade 8 FSA Mathematics Practice Test Guide

ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu

Introduction to MATLAB

ENGG1811 Computing for Engineers Week 1 Introduction to Programming and Python

QUICK INTRODUCTION TO MATLAB PART I

What s New in Blackboard Faculty Tutorial

CCBC Math 081 Order of Operations Section 1.7. Step 2: Exponents and Roots Simplify any numbers being raised to a power and any numbers under the

Digital Image Analysis and Processing CPE

Introduction to Programming

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

SECTION 5: STRUCTURED PROGRAMMING IN MATLAB. ENGR 112 Introduction to Engineering Computing

AN INTRODUCTION TO MATLAB

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

ADD AND NAME WORKSHEETS

ME 1020 Engineering Programming with MATLAB. Chapter 1 In-Class Assignment: 1.1, 1.3, 1.13, Topics Covered:

MathPad Plus v Basics

ENGR 1181 MATLAB 05: Input and Output

Introduction to MATLAB

Our Strategy for Learning Fortran 90

Chapter 1 Introduction to MATLAB

Laboratory 1 Octave Tutorial

Lesson 1: Creating and formatting an Answers analysis

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB?

Transcription:

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

Introduction 2

Chapter l Starting with MATLAB This chapter describes: MATLAB windows Command Window in detail How to do basic arithmetic Create basic variables Introductory script files 3

Current Folder Window Starting MATLAB, MATLAB Windows Workspace Window Command History Window Command Window 4

MATLAB windows Window Command Window Figure Window Purpose Main window, enters variables, runs programs. Contains output from graphic commands. Editor Window Help Window Command History Window Workspace Window Current Folder Window Creates and debugs script and function files. Provides help information. Logs commands entered in the Command Window. Provides information about the variables that are stored. Shows the files in the current folder. 5

Command Window: The Command Window is MATLAB 's main window and opens when MATLAB is started. Figure Window opens automatically after any command that draws a graph. 6

Editor Window: Use Editor Window to write and debug MATLAB scripts. Open with edit command. 7

Help Window: Get Help Window by clicking on Help icon (question mark) in tool strip 8

Command Window is MATLAB s main window. Use it to: Execute commands Open other windows Run programs that you ve written 9

Basic procedure 1. At prompt (>>), type in MATLAB command 2. Press ENTER key 3. MATLAB displays result in Command Window, followed by a prompt 4. Repeat from step 1 10

Notes on Command Window To start a command, make sure cursor is next to prompt MATLAB won t respond until you press ENTER It then executes only last command Commands before last one may still be visible, but MATLAB doesn t execute them Can type several commands in same line by putting a comma between commands Hard to read, so don t do this often If command too long to fit on line, can continue to next line by typing ellipsis (3 periods, i.e., ) and then pressing ENTER 11

Notes on Command Window When cursor is in bottom command line: key moves cursor one character to left key moves cursor one character to right key recalls preceding command key recalls command that follows one being displayed. 12

Notes on Command Window PAGE-UP key moves up to previous commands in a window-size at a time. PAGE-DOWN key moves down to previous commands in a window-size at a time. BACKSPACE key deletes character to left of cursor. DELETE key deletes character to right of cursor. 13

Notes on Command Window To quickly execute a previous command but with minor changes. 1. Recall command with up- and down-arrow keys. 2. Use left- and right-arrow keys to move to characters to be altered. 3. Use BACKSPACE or DELETE to remove old character, then type new character. 4. Press ENTER to execute modified command. 14

Semicolon (;) Notes on Command Window When typed at end of command, suppresses output. (Only prompt displayed at next line) Useful for preventing display of large outputs Percent sign(%) When typed at beginning of line, MATLAB treats line as a comment and doesn t execute line. clc command Clears Command Window display Up and down arrows still bring back previous commands 15

Command History Window Command History Window Shows previous commands, including ones from previous MATLAB sessions Double-clicking on command puts it in Command Window and executes it Can drag command to Command Window, make changes in command, then execute it To clear one or more commands, select the lines to delete, right click, choose Delete Selection To clear entire history, right click, select Clear Command History 16

Arithmetic in MATLAB Symbols for arithmetic are: Operation Symbol Example Addition + 5 + 3 Subtraction 5 3 Multiplication * 5 * 3 Right division / 5 / 3 Left division \ 5 \ 3 = 3 / 5 Exponentiation ^ 5 ^ 3 (means 5 3 = 125) 17

Order in which MATLAB does arithmetic Precedence First Second Third Fourth Mathematical Operation Parentheses. For nested parentheses, the innermost are executed first. Exponentiation. Multiplication, division (equal precedence). Addition and subtraction. 18

Using Matlab as Calculator 19

Using Matlab as Calculator 20

1.4 display Formats Can control display of numbers with format command Once enter command, format stays the same until another format command. Default format is fixed point with four digits to right of decimal point (called short) Format only affects display of numbers. MATLAB always computes and saves numbers in full precision 21

Display formats 22

Display formats 23

1.5 ELEMENTARY MATH BUILT-IN FUNCTIONS 24

1.5 ELEMENTARY MATH BUILT-IN FUNCTIONS 25

1.5 ELEMENTARY MATH BUILT-IN FUNCTIONS 26

1.5 ELEMENTARY MATH BUILT-IN FUNCTIONS 27

1.5 ELEMENTARY MATH BUILT-IN FUNCTIONS 28

1.5 ELEMENTARY MATH BUILT-IN FUNCTIONS 29

1.6 DEFINING SCALAR VARIABLES A variable is a name made of a letter or a combination of several letters (and digits) that is assigned a numerical value. Once a variable is assigned a numerical value, it can be used in mathematical expressions, in functions, and in any MATLAB statements and commands. A variable is actually a name of a memory location. The Assignment Operator In MATLAB the = sign is called the assignment operator. The assignment operator assigns a value to a variable. Variable_ name = A numerical value, or a computable expression 30

1.6 DEFINING SCALAR VARIABLES 31

1.6 DEFINING SCALAR VARIABLES 32

1.6 DEFINING SCALAR VARIABLES 33

1.6 DEFINING SCALAR VARIABLES A variable that already exists can be reassigned a new value: 34

1.6 DEFINING SCALAR VARIABLES Once a variable is defined it can be used as an argument in functions. For example: 35

1.8 SCRIPT FILES So far all the commands were typed in the Command Window and were executed when the Enter key was pressed. A different (better) way of executing commands with MA TLAB is first to create a file with a list of commands (program), save it, and then run (execute) the file. When the file runs, the commands it contains are executed in the order that they are listed. Files that are used for this purpose are called script files. A script file is a sequence ofmatlab commands, also called a program. Using a script file is convenient because it can be edited (corrected or otherwise changed) and executed many times. Script files are also called M-files because the extension.m is used when they are saved. 36

1.8 SCRIPT FILES 37

1.9 EXAMPLES OF MATLAB APPLICATIONS Sample Problem 1-1: Trigonometric identity 38

1.9 EXAMPLES OF MATLAB APPLICATIONS Sample Problem 1-2: Geometry and trigonometry Four circles are placed as shown in the figure. At each point where two circles are in contact, they are tangent to each other. Determine the distance between the centers C2 and C4. The radii of the circles are: R1 = 16mm, R2 = 6.5mm, R3 = 12 mm, and R4 = 9.5mm. 39

1.9 EXAMPLES OF MATLAB APPLICATIONS Sample Problem 1-2: Geometry and trigonometry 40

1.9 EXAMPLES OF MATLAB APPLICATIONS Sample Problem 1-2: Geometry and trigonometry 41

1.9 EXAMPLES OF MATLAB APPLICATIONS Sample Problem 1-2: Geometry and trigonometry 42