Math 2250 MATLAB TUTORIAL Fall 2005

Similar documents
LAB 1 General MATLAB Information 1

Introduction to Engineering gii

A very brief Matlab introduction

A Guide to Using Some Basic MATLAB Functions

Dr Richard Greenaway

Getting Started with MATLAB

General MATLAB Information 1

Matlab Introduction. Scalar Variables and Arithmetic Operators

Computer Programming in MATLAB

Introduction to Scientific and Engineering Computing, BIL108E. Karaman

A QUICK INTRODUCTION TO MATLAB

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

Lab 1 Intro to MATLAB and FreeMat

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started

Chapter 1 Introduction to MATLAB

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

Introduction to MATLAB

Arithmetic and Logic Blocks

3+2 3*2 3/2 3^2 3**2 In matlab, use ^ or ** for exponentiation. In fortran, use only ** not ^ VARIABLES LECTURE 1: ARITHMETIC AND FUNCTIONS

A General Introduction to Matlab

Introduction to Matlab

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

A Brief Introduction to MATLAB

Mathworks (company that releases Matlab ) documentation website is:

Introduction to Unix and Matlab

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

Lecturer: Keyvan Dehmamy

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

Introduction to MATLAB

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

Finding, Starting and Using Matlab

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

Matlab Workshop I. Niloufer Mackey and Lixin Shen

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.

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

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:

Introduction to MATLAB

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

Chapter 2 (Part 2) MATLAB Basics. dr.dcd.h CS 101 /SJC 5th Edition 1

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

Laboratory 1 Octave Tutorial

Introduction to MATLAB Practical 1

ARRAY VARIABLES (ROW VECTORS)

Introduction to GNU-Octave

EE 216 Experiment 1. MATLAB Structure and Use

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

Matlab Tutorial. Get familiar with MATLAB by using tutorials and demos found in MATLAB. You can click Start MATLAB Demos to start the help screen.

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:

Advanced features of the Calculate signal tool

MATLAB Constants, Variables & Expression. 9/12/2015 By: Nafees Ahmed

Introduction to MATLAB Programming

SF1901 Probability Theory and Statistics: Autumn 2016 Lab 0 for TCOMK

Chapter 1: An Overview of MATLAB

Dr Richard Greenaway

Getting Started with MATLAB

The value of f(t) at t = 0 is the first element of the vector and is obtained by

INTRODUCTION TO MATLAB PROGRAMMING Lec 1.1: MATLAB Basics

Lecture 1 arithmetic and functions

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

1 Introduction to Matlab

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

AMS 27L LAB #1 Winter 2009

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

AN INTRODUCTION TO MATLAB

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

VARIABLES Storing numbers:

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

What is MATLAB and howtostart it up?

How to Use MATLAB. What is MATLAB. Getting Started. Online Help. General Purpose Commands

Some elements for Matlab programming

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

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

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

A. Matrix-wise and element-wise operations

Section 1: Numerical Calculations

An Introductory Guide to MATLAB

Introduction to MATLAB

Programming in Mathematics. Mili I. Shah

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

Numerical Methods Lecture 1

MORE MATLAB. MATLAB variables

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

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT

2.0 MATLAB Fundamentals

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

MATLAB Functions and Graphics

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

This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms:

The Very Basics of the R Interpreter

Excel R Tips. is used for multiplication. + is used for addition. is used for subtraction. / is used for division

MATH 3511 Basics of MATLAB

Introduction to Matlab

Built-in Types of Data

PIV Programming. Today s Contents: 1. Matlab Programming 2. An example of PIV in Matlab code 3. EDPIV 4. PIV plugin for ImageJ 5.

MATLAB/Octave Tutorial

Class #15: Experiment Introduction to Matlab

PART 1 PROGRAMMING WITH MATHLAB

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

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

Transcription:

Math 2250 MATLAB TUTORIAL Fall 2005 Math Computer Lab The Mathematics Computer Lab is located in the T. Benny Rushing Mathematics Center (located underneath the plaza connecting JWB and LCB) room 155C. The hours for the labs are: Monday to Thurday 8:00 a.m. to 8:00 p.m. Friday 8:00 a.m. to 6:00 p.m. Closed on weekends and university holidays Students are also welcome to use the computer lab in 205 South Physics. This is a good option for students who need to use the lab on weekends as well as earlier or later than the math lab hours. More information about the lab can be found at: http://www.math.utah.edu/ugrad/lab.html Account and Logging on Almost all students registered in any math class will aready have accounts set-up. These are created from university class lists, so students who registered late may not be included yet. Your login name is of the form c-azbx where azbx are as follows: a is the first letter of your last name z is the last letter of your last name b is the first letter of your first name x is your middle initial If someone has the same initial as you, your login may be c-azbx1 or c-azbx2, etc. Passwords Your initial password is azbx (as above) followed by the last 4 digits of your student ID number. If you have a login name with a number at the end, the number is NOT in your password. Your login name and password are all lowercase with no spaces. Common Desktop Environment Once logged in, you will see the common desktop environment (CDE) which is the default environment of our unix based system. The first thing to look for is the computer icon towards the bottom of the screen. Click on this icon to open an xterm window. Changing password - On the xterm window, type passwd then hit enter. You will then be prompted to enter your initial password followed by your desired new password. Your password should consist of at least 6 characters (upper and lower case letters and digits). Loggin out In CDE, there is a logout or exit icon at the bottom of your desktop. You can also logout by right-clicking on your mouse and then choosing the logout option.

MATLAB MATLAB is a tool for doing numerical computations with matrices and vectors. It can also display information graphically. To start MATLAB, type matlab on your xterm then enter. A MATLAB 7 window will then appear. Saving your session The first thing to do when you begin a session is to save the session in case you will need it later. This is done by typing the following on the command window: >> diary filename.txt To turn it off or before you exit type >> diary off When finished, you can edit this file using external text editor and print it out. Arithmetic operations You can do the usual arithmetic operations also >> 3+4 >> 5*(4+7) >> (3+4)^2/7 You can define a variable as well >> y = 5^3 If you put a semi-colon at the end of the command, the answer will be suppressed. >> 3+4; Another nice feature of MATLAB is that you can define how your answer should look like, i.e. in decimal form, fractional form, etc. Type the following to see the difference. >> format rat >> format long >> format short By using format rat, your answer is given as ratio of small integers (fractional form). By using format long, you will get an answer in a decimal form with 15 digits accuracy. The default format is format short where the answer is given as a 5-digits decimal. Scalar Functions You can also compute the numerical value of usual functions: sin sine function (argument in radian) asin inverse sine cos, tan acos, atan exp exponential log natural log abs absolute value sqrt square root round round to nearest integer floor round to next smallest integers ceil round to next largest integer rem remainder after division >> pi >> sin(pi) >> asin(0) >> round(3/4)

Getting help You can bring a help window by clicking Help button at the very top of the window and selecting Full Product Family Help. If you already know the function call, you can type >> help sin Or if you are looking for a particular command >> lookfor matrix This will bring a list of possible command. The list may be long; to stop the listing, press CTRL-C. Matrix and Vector MATLAB is designed to handle matrix/vector computation very well. You will find this useful as you are learning more linear algebra in this course. To enter the matrix 1 2 3 4 and store it in a variable a, do this: >> a = [1 2; 3 4] >> b = [1 2; 0 1] You can do matrix multiplication, summation, and so on >> a+b >> a*b >> b*a A vector is defined in a similar way >> u = [0;1] % this gives you a column vector >> v = [0 1] % this gives you a row vector Be careful in being consistent when you are defining vector. For example you cannot add a row vecotr to a column vector >> u+v >> u+v' The apostrophe ' sign can be used to transpose a vector/matrix. A brief but slightly more detailed tutorial on matrix/vector computations can be found at http://www.math.utah.edu/computing/ms/matlab/matlab.html Graphing To make a graph of sin(x) in the interval [0 5], we can do the following >> x = [0:0.2:10]; % define a vector with components ranging from 0 to 10 with steps 0.2 >> y = sin(x); >> plot(x,y)

Printing You can print from MATLAB by finding the printer icon or go to File at the top of the window and selecting Print. Choose the printer name appropriately. The printer names are lcb115 LCB 115 computer lab mc155c spps Math Center 205 South Physics You can also print a file from xterm window by typing lpr -P printername M-Files MATLAB can execute a sequence of statements stored in diskfiles. Such files are called M-files" because they must have the file type of.m as the last part of their filename. Much of your work with MATLAB will be in creating and refining M-files. M-files can be created using the built-in MATLAB editor as well as local text editor (emacs, nedit, vi). To call the built-in text editor, click File followed by New then select M-file. There are two types of M-files: script files and function files. They essentially serve the same purpose but sometimes it makes more sense to choose one over the other. For example, you can store huge amount of data in script files but use function file to do a task that's repetitious. Script files Save it as matrixa.m A= [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]; Be careful when naming these files as you cannot use any of the defined MATLAB function name. Choose a name that's somewhat cryptic - matrixa.m instead of matrix.m You can run script files directly from the built-in editor by clicking on the Run button (the one with page and arrow icon) or you can call it from the MATLAB command window >> matrixa Function files function y = sincos(x1,x2) % compute y = sin(x1)^2 + sin(x2)^2 y = sin(x1)^2 + sin(x2)^2; Save the file with name corresponding to the function name. Here, for example, you should save it as sincos.m Now, you can call this from MATLAB by typing >> y = sincos(pi,pi);

function dum = plotx(a,b) % plot x^2 on the interval [a,b] step = (b-a)/10; x = [a : step : b]; y = x.^2; % the dot in front of ^ is to square x element by element plot(x,y) dum =1; Save the file as plotx.m and run it from MATLAB >> z=plotx(-1,1); Now, try to modify this file to plot x^3 instead of x^2. REFERENCES A very detailed and good introduction to MATLAB is the MATLAB primer written by Kermit Sigmon which can be accessed online through several sites such as: http://www.mines.utah.edu/gg_computer_seminar/matlab/matlab.html We can also send you a hard pdf copy if you are interested in learning more about MATLAB.