Introduction to Unix and Matlab

Similar documents
MATLAB Project: Getting Started with MATLAB

2.0 MATLAB Fundamentals

Eric W. Hansen. The basic data type is a matrix This is the basic paradigm for computation with MATLAB, and the key to its power. Here s an example:

Math 2250 MATLAB TUTORIAL Fall 2005

Introduction to MATLAB

Introduction to MATLAB

3 An Introductory Demonstration Execute the following command to view a quick introduction to Matlab. >> intro (Use your mouse to position windows on

Computer Project: Getting Started with MATLAB

MATLAB Project: Getting Started with MATLAB

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

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

Introduction to MATLAB

MATLAB COURSE FALL 2004 SESSION 1 GETTING STARTED. Christian Daude 1

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

12 whereas if I terminate the expression with a semicolon, the printed output is suppressed.

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

Tiny Instruction Manual for the Undergraduate Mathematics Unix Laboratory

Using the Zoo Workstations

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

Math Scientific Computing - Matlab Intro and Exercises: Spring 2003

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.

Introduction to Matlab

LAB 1 General MATLAB Information 1

AMATH 352: MATLAB Tutorial written by Peter Blossey Department of Applied Mathematics University of Washington Seattle, WA

Introduction to MatLab. Introduction to MatLab K. Craig 1

1 Introduction to Matlab

AMS 27L LAB #1 Winter 2009

! The MATLAB language

Learning from Data Introduction to Matlab

Matlab Introduction. Scalar Variables and Arithmetic Operators

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

An Introductory Guide to MATLAB

Introduction to MATLAB

Introduction to MATLAB

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.

Introduction to MATLAB

Matlab Lecture 1 - Introduction to MATLAB. Five Parts of Matlab. Entering Matrices (2) - Method 1:Direct entry. Entering Matrices (1) - Magic Square

Computational Modelling 102 (Scientific Programming) Tutorials

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

Getting To Know Matlab

FreeMat Tutorial. 3x + 4y 2z = 5 2x 5y + z = 8 x x + 3y = -1 xx

Editors in Unix come in two general flavours:

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

AMS 27L LAB #2 Winter 2009

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

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

Matlab Tutorial and Exercises for COMP61021

16.06/16.07 Matlab/Simulink Tutorial

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

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

CSE/NEUBEH 528 Homework 0: Introduction to Matlab

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

Lab 1 Intro to MATLAB and FreeMat

INTRODUCTION TO MATLAB

An Introduction to MATLAB II

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

ELEN E3084: Signals and Systems Lab Lab II: Introduction to Matlab (Part II) and Elementary Signals

Introduction to MATLAB

Matlab Tutorial for COMP24111 (includes exercise 1)

Matlab Tutorial 1: Working with variables, arrays, and plotting

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

Getting started with MATLAB

The Very Basics of the R Interpreter

Math Sciences Computing Center. University ofwashington. September, Fundamentals Making Plots Printing and Saving Graphs...

Introduction to Mathcad

Finding, Starting and Using Matlab

Introduction to Matlab to Accompany Linear Algebra. Douglas Hundley Department of Mathematics and Statistics Whitman College

Matlab Handout Nancy Chen Math 19 Fall 2004

Lab copy. Do not remove! Mathematics 152 Spring 1999 Notes on the course calculator. 1. The calculator VC. The web page

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

Introduction to MATLAB

University of Alberta

Introduction to Matlab

Choose the file menu, and select Open. Input to be typed at the Maple prompt. Output from Maple. An important tip.

CSE/Math 456 and CSE/Math 550 Matlab Tutorial and Demo

Introduction to Matlab

MATLAB Lecture 1. Introduction to MATLAB

Getting Started with MATLAB

Mathworks (company that releases Matlab ) documentation website is:

Getting Started with MATLAB

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

General MATLAB Information 1

Getting Started With UNIX Lab Exercises

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

Computer Packet 1 Row Operations + Freemat

A Tour of Matlab for Math 496, Section 6

HERIOT-WATT UNIVERSITY DEPARTMENT OF COMPUTING AND ELECTRICAL ENGINEERING. B35SD2 Matlab tutorial 1 MATLAB BASICS

Introduction to Scientific Computing with Matlab

Dr Richard Greenaway

Introduction to MATLAB

Physics 326G Winter Class 2. In this class you will learn how to define and work with arrays or vectors.

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

YOGYAKARTA STATE UNIVERSITY MATHEMATICS AND NATURAL SCIENCES FACULTY MATHEMATICS EDUCATION STUDY PROGRAM

MATLAB Tutorial. Primary Author: Shoumik Chatterjee Secondary Author: Dr. Chuan Li

PART 1 PROGRAMMING WITH MATHLAB

ECE Lesson Plan - Class 1 Fall, 2001

MAT 275 Laboratory 1 Introduction to MATLAB

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

ECE 3793 Matlab Project 1

Transcription:

Introduction to Unix and Matlab 1 Introduction to the Unix System 1.1 Login Pick any machine in Room 451; the screen is probably dark. If so, press the [return] key once or twice. You should see something like: login: Password: Your login name (or sometimes called user name) is your last name or what you have been given by your instructor, which are all in lowercase. For example, Robert Jones has/has been given the login name jones. Don t forget to press the [return] key after you type your login name this is what transmits what you ve written on the screen to the computer. You ll now see the line password:. For now, type the password you ve been given and press [return]; at the end of the session, you ll probably want to change your password. If you ve done this correctly, the machine will chug along for a bit and then the graphical user interface will magically appear. If you ve used either a Macintosh or a PC with Windows, you ll find that the machines behave in a somewhat similar manner. You should see a small window labelled cmdtool(console), and a larger window labelled just cmdtool. As a general rule, you should leave the console window alone any system messages, such as error messages, or the message that there s new mail for you, will be displayed on the console. A cmdtool window, including the console window, is one which behaves more or less like a standard terminal you can type in commands and the machine will obey. You can have a number of cmdtool windows open at the same time. You can see that there are three buttons on the mouse. The left, the middle and the right are called the select, adjust and menu buttons, respectively. Move the mouse pointer to a blank region of the screen; press the menu button and hold it down. While this button is down, a menu appears; move the pointer into the little triangle at the right of the programs item, and another menu will appear, giving a list of standard programs. We re interested in three of these: the command tool, the text editor, and the file manager. Now select command tool from this menu by moving the pointer to it and releasing the menu button. In a few seconds a window with the % prompt appears. Move the mouse to this cmdtool window and press the select (left) button, making this the active window. Try resizing the window 1

by dragging one of the corners around. You can move the entire window around by clicking in the middle of the top border and dragging. Double-clicking in the top of the window makes it take up most of the screen; double clicking again reverses the process. Clicking on the little triangle in the upper left iconifies the window. Double clicking on the icon restores the cmdtool window. Try all of this. To get rid of the cmdtool window, if that s what you want, click and hold the menu button when the pointer is on the top of the window, and select the quit option. (The close option will produce an icon, not terminate the process.) 1.2 Finishing up When you re done for today, you need to shut down all the programs you started. If you are the first time to use your current account, you may want to change your password given by your instructor. If so, type the command passwd and press the [return] key. Then follow the introduction given by the machine to change your password. Now to log out, click with the button logout at the right-top corner of the screen. WARNING: If you don t log out, then anyone else can sit down at the machine, and pretend to be you, reading and copying your files, etc. Always log out before you leave the lab. 1.3 Appendix A: Some basic UNIX commands man This command displays the manual pages. For instance, typing man ls will display the manual page for the command ls, which is explained below. ls Displays a listing of the files in the current directory. Similar to the command dir in DOS. cd Changes your current directory. For example, typing cd /usr will make your current directory the usr directory. Typing cd by itself will return you to your home directory. Similar to the command cd in DOS. rm Deletes a file or files. For instance, typing rm hello.txt will delete the file named hello.txt. Typing rm hello.* will delete all files whose names start with the string hello.. Similar to the command del in DOS. cat Displays the contents of a file. Similar to the command type in DOS. vi A command that invokes a visual edit. This editor is rather complex to use and is not recommended for novices. emacs An easier to use editor. Type control-x, control-c to exit emacs. 2

mail A not very easy to use mail system. pine Pine is an easy to use mail system. It allows you to send and receive and read email messages. matlab This command starts matlab on the Department of Mathematics computers. exit Closes the current window or process. NOTE This does not log you out of the machine. passwd Changes your password. The computer will ask you for your old password and will ask you to specify a new password. Don t forget your new password. lpr Print a file on the laser printer. For example, typing lpr hello.txt will print the file named hello.txt on the laser printer. 1.4 Appendix B: Some basic vi commands You can use vi editor to edit a file. Type the command vi to edit enter text editor, then any of following commands (in command mode, unless preceded by a :): a to add text. cc to substitute a line with a string (enters insert mode). cw to substitute, or change, a word with a string (enters insert mode). dd to delete the entire line the cursor is on. dw to delete the word, or portion of word, under and after the cursor. h to move left, or west, one character. i to insert text under the cursor (enters insert mode). j to move down, or south, one line. k to move up, or north, one line. l to move right, or east, one character. o to insert text on a new blank line after the current line (enters insert mode). O to insert text on a new blank line before the current line (enters insert mode). s to substitute a character with a string (enter insert mode). u to undo the previous command. x to delete the character under the cursor. :q tp quit vi. :q! to quit vi, without writing changes. 3

:w to save, or write a file. key [esc] to quit the insert mode. 2 E-mail You may use many different mail tools to read, send and edit your mails. Here we are going to study a simple e-mail tool: mail. mail is a comfortable, flexible, interactive program for composing, sending and receiving electronic messages. While reading messages, mail provides you with commands to browse, display, save, delete, and respond to messages. While sending mail, mail allows editing and reviewing of messages being composed, and the inclusion of text from files or other messages. Incoming mail is stored in the system mailbox for each user. This is a file named after the user in /var/spool/mail. mail normally looks in this file for incoming messages, but you can use the MAIL environment variable to have it look in a different file. When you read a message, it is marked to be moved to a secondary file for storage. This secondary file, called the mbox, is normally the file mbox in your home directory. This file can also be changed by setting the MBOX environment variable. Messages remain in the mbox file until deliberately removed. If no recipient is specified, mail attempts to read messages from the system mailbox. To get help about how to use mail, type man mail. Some commands: mail, help, q, x, r, vi. For example, % mail % mail jones@math.ukans.edu 3 Matlab 3.1 Data representation MATLAB s data representations are all interpretations of one basic structure, the matrix. This is a rectangular array of numbers, stored and manipulated internally using the computer s floating point format and operations. The basic matrix data structure can have special interpretations in a number of situations, including: matrix A real matrix with number entries. For example, >> A = [.1.2;.3.4] This creates a 2-by-2 real matrix and 4

assigns it to variable A vector A matrix with only one row or column. For example, >> v = [.1.2.3.4] This creates a 4 component vector scalar A 1-by-1 matrix. For example, >> a =.3 complex scalar A 1-by-1 complex matrix. For example, >> b =.3 +.4i complex matrix A pair of matrices, the real and imaginary parts. For example, >> C = [.1.2;.3.4] + [.5.6;.7.8]*i flint A scalar whose value is an integer. Flints with fewer than nine decimal digits are printed without a decimal point or exponent. For example, >> f = 3 character A flint, usually in the range from 32 to 127, interpreted as the ASCII code for a printable character. For example, >> ch = a This create a character a and assigns it to variable ch string A row vector of characters, together with an internal string tag. For example, >> st = Hello World string matrix A matrix with several rows, each of which is a string. For example, >> sm = [ Hello ; World ] The toolbox Symbolic Math Toolbox extends MATLAB s operations on strings and string matrices to include: symbolic expression A string, representing a mathematical quantity. For example, 5

>> se = 1/(5+4*cos(x)) symbolic variable An isolated character in the range a : z, excluding i and j. For example, >> x symbolic constant A symbolic expression which does not contain a symbolic variable. example, For >> (1+sqrt(5))/2 symbolic matrix A string matrix each of whose rows contains the same number of symbolic expressions, separated by commas. For example, >> [cos(t), sin(t); -sin(t), cos(t)] You can build expressions with the usual arithmetic operators and precedence rules: + addition - subtraction * multiplication / right division \ left division ˆ power. 3.2 How to plot data in MATLAB To display 2-dimensional data in MATLAB, use the function plot(), whose argument needs to be a vector. Note that a command plot(sin(t)) makes no sense unless MATLAB knows what t is (It does have its own algorithms for sine, cosine, etc. ). Proceed thusly to graph the sine function on the interval [0,4*pi] using 125 equally spaced points (enter the commands as written to the right of the MATLAB prompt >>): >>t = 0:4*pi/125:4*pi This creates a vector named t with entries [0,4*pi/125,8*pi/125,...,4*pi] Notice that this entire list of numbers was displayed on the screen, which is not generally what you want. To SUPPRESS the display, end the line with a semi-colon(;)! 6

>> x = sin(t); This creates a vector named x with entries [sin(0),sin(4*pi/125),...,sin(4*pi)] >>plot(x) >>plot(t,x) Notice the units... What s the difference? >>y = sin(t+.25); >>z = sin(t+.5); Phase shift Another >>hold on The next graph drawn will not erase the present one. >>plot(t,y, -- ) >>plot(t,z,. ) >>title( sine function with phase shift ) >>xlabel( t ) >>ylabel( sin(t+) ) Self-explanatory >>hold off >>plot(x,z) What is this? >>subplot(3,1,1), plot(x) >>subplot(3,1,2), plot(y) >>subplot(3,1,3), plot(z) Subplot(m,n,p) creates an m by n array of plots on a single screen, and refers to the pth one, counting from the upper left. Experiment with this a bit, till you re sure how it works. To get a printout from MATLAB: >>print -dps2 Sends whatever s displayed to the printer; once something s gone from the screen, it can t be printed. The -dps2 makes it print faster; just 7

>>print -dps2 filename.ps plain "print" will also work. Command to save the current image as a text file with the name "filename.ps". At some later time, this can be sent to the printer by using the command %lp filename.ps (this command is issued from outside MATLAB, in a cmdtool window.) VERY IMPORTANT!! MATLAB has an extremely useful help facility. If you don t know how the print command works, do >>help print and similarly for everything else. In the next section, you may want to type help eul at some point... Before beginning the next section, do >>subplot(1,1,1) to get back to a single figure. There are other ways to do this, including >>clf 3.3 Linear algebra Example: >> A = [2/3 2/3 1/3; 2/3-1/3-2/3; 1/3-2/3 2/3] This creates a 3-by-3 matrix and assigns it to variable A >> b = [1; 1; 1] This creates a 3-component column vector and assigns it to variable b >> who to check how many variables we have >> x = A\b to solve the linear system A*x = b >> y = inv(a)*b another way to solve A*x = b, where inv(a) is the inverse of A >> x-y check if x is equal to y >> z = det(a) This calculates the determinant of A 8

and assigns it to variable z >> [V,D] = eig(a) What is this for? get information by using help eig. Can you obtain the all eigenvalues and eigenvectors of A? >> A A this calculates the multiplication of A and its transpose. What can you say about the matrix from the result? Try to find the eigenvalues and eigenvectors of A and solve linear system Ax = b, where 1 1 2 1 A = 2 0 1 b = 0. (1) 3 1 3 1 3.4 Symbolic Mathematics Differentiation and Integration Calculus Example: >> f = 1/(5+4*cos(x)) Stores the symbolic expression defining the function in f >> ezplot(f) produces the plot of f(x) >> f1 = diff(f, x ) differentiates f(x) once with respect to its symbolic variable x to produce its first derivative >> f2 = diff(f, x,2) differentiates f(x) twice with respect to its symbolic variable x to produce its first derivative >> ezplot(f1) >> hold on >> ezplot(f2) >> hold off What are these commands for? Use the command help to find them >> F = int(f) calculate the indefinite integral of f(x) with respect to its symbolic variable x >> ezplot(f) 9

>> F1 = int(f, x, 0, 1) calculate the definite integral of f with respect to x from 0 to 1 >> eval(f1) get the numeric of F1 Could you try this function f(x) = e x2? Calculate its first, second derivatives, first anti-derivative, and definite integral of f(x) from x = 0 to x = inf (the infinite symbol used in matlab). Don t forget to plot these functions. 3.5 Packages of ODE Solvers >> dfield plot the direction fields for scalar ODE >> ppp plot the direction fields for systems of two ODEs 3.6 Exit from MATLAB >> quit Exit from MATLAB 10