Chapter 1: An Overview of MATLAB

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

Desktop Command window

MATLAB The first steps. Edited by Péter Vass

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

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3.

Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming usin

CITS2401 Computer Analysis & Visualisation

Introduction to MATLAB

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

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

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

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT

Introduction to MATLAB

MATLAB Introduction to MATLAB Programming

Starting with a great calculator... Variables. Comments. Topic 5: Introduction to Programming in Matlab CSSE, UWA

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

1 Overview of the standard Matlab syntax

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing

Math 2250 MATLAB TUTORIAL Fall 2005

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

Matlab Programming Introduction 1 2

Matlab Programming MET 164 1/24

Class #15: Experiment Introduction to Matlab

MATLAB Project: Getting Started with MATLAB

Chapter 1 Introduction to MATLAB

Introduction to Engineering gii

MATLAB Project: Getting Started with MATLAB

EGR 111 Introduction to MATLAB

Matlab- Command Window Operations, Scalars and Arrays

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

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

Finding, Starting and Using Matlab

Lab 1 Intro to MATLAB and FreeMat

Introduction to MATLAB

Dr Richard Greenaway

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:

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

ENGR 1181 MATLAB 05: Input and Output

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

Teaching Manual Math 2131

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

Introduction to MATLAB

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

2.0 MATLAB Fundamentals

MAT 275 Laboratory 1 Introduction to MATLAB

Chapter 4: Programming with MATLAB

LAB 2: Linear Equations and Matrix Algebra. Preliminaries

An Introduction to MATLAB See Chapter 1 of Gilat

Introduction to MATLAB

MATLAB Part 1. Introduction

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

MATLAB. Devon Cormack and James Staley

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

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

Digital Image Analysis and Processing CPE

APPM 2460 Matlab Basics

Introduction to MATLAB

MATLAB Basics 2 simple calculations and use

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

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

ME 121 MATLAB Lesson 01 Introduction to MATLAB

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

Introduction to Matlab

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

Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.

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

Matlab Introduction. Scalar Variables and Arithmetic Operators

Colorado State University Department of Mechanical Engineering. MECH Laboratory Exercise #1 Introduction to MATLAB

Programming in Mathematics. Mili I. Shah

MATLAB = MATrix LABoratory. Interactive system. Basic data element is an array that does not require dimensioning.

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

ECE Lesson Plan - Class 1 Fall, 2001

powerone for iphone/ipad/ipod Touch Help

ELEMENTARY MATLAB PROGRAMMING

EXCEL 98 TUTORIAL Chemistry C2407 fall 1998 Andy Eng, Columbia University 1998

Introduction to Scientific and Engineering Computing, BIL108E. Karaman

Unix Computer To open MATLAB on a Unix computer, click on K-Menu >> Caedm Local Apps >> MATLAB.

MATLAB - Lecture # 4

LAB 1 General MATLAB Information 1

(Creating Arrays & Matrices) Applied Linear Algebra in Geoscience Using MATLAB

MATLAB for beginners. KiJung Yoon, 1. 1 Center for Learning and Memory, University of Texas at Austin, Austin, TX 78712, USA

Computer Programming in MATLAB

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

the Enter or Return key. To perform a simple computations type a command and next press the

Edward Neuman Department of Mathematics Southern Illinois University at Carbondale

Week 1: Introduction to R, part 1

PART 1 PROGRAMMING WITH MATHLAB

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

AMS 27L LAB #2 Winter 2009

Getting Started. Chapter 1. How to Get Matlab. 1.1 Before We Begin Matlab to Accompany Lay s Linear Algebra Text

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

Mathworks (company that releases Matlab ) documentation website is:

Maple Quick Start. Maplesoft, a division of Waterloo Maple Inc.

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

Chapter 2. MATLAB Fundamentals

Welcome to EGR 106 Foundations of Engineering II

Introduction to Programming for Biology Research

Introduction to MATLAB

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

Introduction to Matlab

Transcription:

Chapter 1: An Overview of MATLAB MATLAB is: A high-level language and interactive environment for numerical computation, visualization, and programming MATLAB can: Be used as a calculator, easily create scalars, vectors and arrays, be used as a programming environment, make sophisticated plots, be used to create models that describe experimental data, solve statistics and probability problems, solve systems of linear algebraic equations, solve differential equations MATLAB is used for: Finite element analysis, computational fluid dynamics, signal processing and communications, image and video processing, control systems, test and measurement, etc. MATLAB is used by: More than a million engineers and scientists in industry and academia

Chapter 1: An Overview of MATLAB Chapter 1 Topics Covered: MATLAB Windows: Current Folder, Command, Workspace, Command History Using MATLAB as a Calculator Mathematical Operators Clearing Windows Assignment Operator Using MATLAB Script Files Creating/Saving/Editing/Executing Script Files Changing the Destination Folder Using the Editor Window Built-In Functions Search Documentation Order of Mathematical Precedence Creating Arrays and using them in Calculations Creating Plots with Arrays (Graphics Window) Creating Arrays Automatically Understanding Error Signals and Error Messages Publishing MATLAB Files

Open MATLAB. Using MATLAB as a Calculator Workspace Window Current Folder Window Command Window Command History Window

Mathematical Operators Type the following commands into the Command Window to solve Problem 1.1(a):

The output of the calculation appears in the Command Window. The semi-colon (;) suppresses output to the Command Window. The Workspace Window shows the names and values of the Variables. The Command History Window shows the entered commands. Previous commands can be accessed quickly by using the Up Arrow and Down Arrow. Try this! Workspace Window Command Window Command History Window

Clear the Command Window by typing clc (and hit enter) into the Command Window.

Remove all of the variables from the Workspace by typing the command clear in the Command Window.

In the previous example, the equals sign (=) is called the Assignment or Replacement Operator. Type in the following session to demonstrate that the Assignment Operator is different than the equals sign in mathematics.

The second command line that was typed in is shown in the Command History Window below. It states the following: Replace variable x with the current contents of variable x plus 1. In the third command line, the caret symbol (^) denotes exponentiation. Replace variable x with the current contents of variable x raised to the second power. Use MATLAB to solve Problem 1.3(a) as shown below:

Using MATLAB Script Files Another method of computation is to create a Script File, which is a way to store commands to be executed in the Command Window. Use the Home/New Script tab to create a new Script File:

The new window that has appeared is called the Editor/Debugger. Use the Editor in MATLAB to solve Problem 1.3(a) by typing the following.

Before saving, change the folder that MATLAB saves files to (the Destination Folder) by pushing the Browse for Folder button:

Select the Desktop folder to be the Destination Folder.

Save the file using the Save button. MATLAB Script File names must start with a letter, and the only special character allowed is the underscore. Numbers are allowed, as long as the number is not the first character. Spaces are not allowed.

The file appears in the Desktop folder as a *.m file. The Script File must be saved prior to execution. Press the green Run button to execute the Script file. Alternatively, pressing the Run button will automatically save the Script File.

The results of the calculation appear in the Command Window. Notice that the values shown in the Workspace Window have changed.

MATLAB will give you clues when you make a mistake in your equations. Delete the last parenthesis in the equation. Notice that the square becomes red, and a red line appears at the line that has the mistake. Also, a squiggly line appears where MATLAB thinks the error lies. Hover the cursor over the red line: EOL stands for End Of Line.

Make the following change in the Script File and save the program using the Save Button under the Editor drop-down menu prior to running the program.

In the modified Script File, the built-in variable pi was used. Other built-in functions exist, as shown in the following session where Problem 1.16(a) is to be solved. Create a new Script File using the New File Button on the Editor. MATLAB gives the new file the temporary name Untitled2.

Type in the following to calculate the equation given in Problem 1.16(a). Get in the habit of typing in the first two commands to clear the command window and to clear the variables stored in memory. Save it to the Desktop using the Save As drop-down menu:

Notice that you can toggle back and forth between the two saved files by clicking on the names in the Editor Window. Try it! Press the Run button to execute the new Script File.

To learn how to use the atan (arc tangent) command, use the Search Documentation window:

The Order of Precedence is a very important concept for properly performing calculations. Using Order of Precedence principles, create a MATLAB script file to calculate Problem 1-15(a).

MATLAB can perform calculations on Arrays with the same ease as it does with single numbers (Scalars). Create and run a new Script File for Problem 1.13:

The new variable x is an Array of six separate numbers that can be acted on as a single unit. The syntax for an Array is Variable_name(Index_number) = Value The Index Number shows where the particular Value resides within the Array. Index numbers are integers starting with 1. Index Number = 1; Value = 0 Notice that the Workspace Window shows all of the Values of variable x:

Calculate the new variable y (Array) using the following equation in terms of variable x:

Plot the resulting y Array versus the x Array :

The Graphics Window appears, showing the graph of y versus x:

Create a new Array x2, use it to create a new Array y2, and plot y2 versus x2:

The Array x2 is created using an automated system, with syntax as follows: Variable_Name = Start : Step : Stop where Start and Stop are the initial and final values (Range), and Step is the step size used to go between Start and Stop. The Workspace Window now shows the new x2 and y2 variables as: <1x11 double> This means that they each have eleven numbers, arranged in one row and eleven columns:

Refine the plot by making the value for Step much smaller:

Notice that the number of values in x2 and y2 is now 1001. What happens when you try to plot y2 versus x? Try it!

Use the comment symbol (%) to comment out the offensive command line. Go to the Publish tab as shown:

Change the Output File Format to PDF:

Publish the file:

The file gets saved to a folder on the Desktop: