AMS 27L LAB #1 Winter 2009

Similar documents
Introduction to Engineering gii

Introduction to Matlab

Lab 1 - Worksheet Spring 2013

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

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

LAB 1 General MATLAB Information 1

General MATLAB Information 1

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

Welcome to EGR 106 Foundations of Engineering II

Dr Richard Greenaway

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

MATLAB QUICK START TUTORIAL

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

Introduction to MATLAB

Consider this m file that creates a file that you can load data into called rain.txt

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT

Introduction to MATLAB

1 Introduction to Matlab

Matlab Programming Introduction 1 2

Basic stuff -- assignments, arithmetic and functions

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

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

Sketchify Tutorial Properties and Variables. sketchify.sf.net Željko Obrenović

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

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

ELEMENTARY MATLAB PROGRAMMING

VARIABLES Storing numbers:

LinReg 2.06 Manual. DePauw University: Physics Department 120 Physics I and 130 Physics II

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

Introduction to MATLAB 7 for Engineers

MAT 275 Laboratory 1 Introduction to MATLAB

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:

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

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

1 Week 1: Basics of scientific programming I

ME 121 MATLAB Lesson 01 Introduction to MATLAB

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

MATLAB Project: Getting Started with MATLAB

AMS 27L LAB #2 Winter 2009

Graphics calculator instructions

Graphical Scientific CALCULATOR

Introduction to MATLAB

9 Using Equation Networks

Introduction. Summary of Contents Section 1 of this document discusses how to use MATLAB as a scalar calculator, and section 2 how

MATLAB Project: Getting Started with MATLAB

Introduction to MatLab. Introduction to MatLab K. Craig 1

Goals for This Lecture:

What is Matlab? The command line Variables Operators Functions

Programming in MATLAB

MATLAB The first steps. Edited by Péter Vass

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

Digital Image Analysis and Processing CPE

PART 1 PROGRAMMING WITH MATHLAB

A Guide to Using Some Basic MATLAB Functions

Computer Project: Getting Started with MATLAB

EGR 111 Introduction to MATLAB

Introduction to MATLAB

Lab 1 Intro to MATLAB and FreeMat

Math 2250 MATLAB TUTORIAL Fall 2005

Lecture 1: What is MATLAB?

Graphics calculator instructions

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

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

2 Making Decisions. Store the value 3 in memory location y

Introduction to Programming

2 A little on Spreadsheets

Python Programming Exercises 1

Applied Calculus. Lab 1: An Introduction to R

Introduction to MATLAB

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

Fixed point algorithmic math package user s guide By David Bishop

Data Types and Basic Calculation

Intrinsic Functions Outline

Laboratory 1: Eclipse and Karel the Robot

Graphing Calculator Tutorial

Computer Programming in MATLAB

Programming in Mathematics. Mili I. Shah

CSI31 Lecture 5. Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial

Chapter 1 Introduction to MATLAB

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

Introduction to MATLAB

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

A Brief Introduction to MATLAB

Excel Tool: Calculations with Data Sets

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

A Short Introduction to Matlab

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

ipad App User Guide Getting Started with Desmos Tables Variables and Sliders Settings, Zoom, and Language Graphable Expressions Supported Functions

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

Beginning C Programming for Engineers

Programming in QBasic

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

Green Globs And Graphing Equations

Chapter 2. Outline. Simple C++ Programs

Numerical Analysis First Term Dr. Selcuk CANKURT

POLYMATH POLYMATH. for IBM and Compatible Personal Computers. for IBM and Compatible Personal Computers

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types

ENGR 105: Introduction to Scientific Computing. Dr. Graham. E. Wabiszewski

Mathematical Operations with Arrays and Matrices

Transcription:

AMS 27L LAB #1 Winter 2009 Introduction to MATLAB Objectives: 1. To introduce the use of the MATLAB software package 2. To learn elementary mathematics in MATLAB Getting Started: Log onto your machine using your ITS login (the same as for your @ucsc email). Note that unless otherwise specified, mouse clicks are left-clicks. 1 Starting MATLAB Matlab is a commercial software package written by The Mathworks. Matlab is an interactive, numerical computation, visualization and technical graphics programming language for applications in engineering and science. The MATLAB environment that enables you to perform computationally intensive tasks such as: data visualization, data analysis, and numeric computation. MATLAB acts like a sophisticated, programmable calculator, allowing you to perform matrix algebra easily. It can also solve ODEs numerically (i.e. approximately, using some scheme to solve the differential equations accurately, if not exactly). Questions about the name MATLAB often arise. MATLAB stands for MATrix LABoratory. See http://www.mathworks.com/access/helpdesk/help/techdoc/matlab.html for an overview of MATLAB. To start MATLAB, click on the Start button in the lower left corner of the screen, go to the Math and Statistics and Graphing menu item, go to the right to MATLAB > R2008b > MAT- LAB R2008b, or double-click the shortcut icon for MATLAB R2008b on your Windows desktop. This may bring up two windows. The top one is the tip of the day, which you may or may not find useful. For today, it is probably too advanced a tip, and you can just click on the close button. This should leave you with the MATLAB Starter window. This has a prompt, >>, and a cursor awaiting instruction. Useful references are available online from the Mathworks site: http://www.mathworks.com/access/helpdesk/help/techdoc/ 2 Getting Help! Matlab has an extensive help facility and a number of demonstration programs. The command help function name is the syntax to ask fro help regarding the function function name. For example, >> help real <Enter> provides a description of the function real(x). The help factility is also divided into categories, and one can access entire lists of functions. For example, 1

>> help elfun <Enter> produces a list of the elementary functions that are available in Matlab. By itself, generates a list of possible categories. >> help <Enter> Type demos for the demonstrations. These are often more complicated than you bargained for. (e.g. check out the cool PEAKS and MODES, which give some idea of the graphics that Matlab is capable of). Type demos for the demonstrations. In the left pane, click the +-sign next to the Getting Started item to expand the list of demos. Exercise #1. Run Working in The Development Environment video, by selecting the item and clicking on Run this demo in the center pane. Don t worry about catching all the information, simply get an idea of how to navigate the MATLAB environment. 3 Stopping Execution You can stop execution of whatever is currently running by pressing Ctrl+C or Ctrl+Break at any time. On Apple Macintosh platforms, you can also use Command+. (the Command key and the period key) to stop the program. 4 Setting up the working directory On the lab PC workstations users can write to the local disk, however, user files are not saved at logout, and the disk is wiped clean when the machine reboots. Data files created by users can be saved to the local hard disk s Desktop temporary us. When you login on a lab workstation, the user s UCSC Home Directory is mapped as X: on the PCs. Files can be copied (dragged) to and from the Home Directory. The Home Directory can also be accessed via SFTP at unix.ic.ucsc.edu. Alternatively, you can save your Matlab files using a USB Flash Drive, or CD-R/RW. Create a folder in your home directory or other device to house the course labs and name it ams27. 5 Recording Your Work It is frequently useful to be able to record what happens in a MATLAB session. For example, to prepare a homework assignment or log a lab session, it is not necessary to copy all of the output from the computer screen. The MATLAB diary command makes this possible. For example, suppose you are doing our first homework assignment and you want to record what you are doing in MATLAB. To do this, choose a name, perhaps hw1 for the file in which you wish to record the output. Then enter diary hw1 at the Matlab prompt. From this point on, everything that appears in the Command Window will also be recorded in the file hw1. When you want to stop recording enter diary off. If you want to start recording again, enter diary on. 2

6 Numbers and operations In Matlab, numbers are what you expect: 12.4 entered after the prompt, followed by <Enter> means exactly that to Matlab: >> 12.4 ans = 12.4 with answer, being the number 12.4 abbreviated as ans by Matlab. Matlab won t do anything other than interpret the command as a number unless you tell it to do more. Note that <Enter> tells Matlab to execute the command contained on that line. The up arrows on the keyboard also work in recalling earlier commands and moving along each line. Simple arithmetic operations are also straightforward: >> 12.4 (48.5 + 342/39) means 12.4(48.5 + 342 39 ), and produces the result: ans = 710.1385 The arithmetic operations recognized by Matlab are: + addition - subtraction / division raise to power Multiple commands can be placed on the same line if separated by a, or a ; : Question 1: What type of number does the following arithmetic operation produce? >> theta=pi; exp(i theta), cos(theta) + i sin(theta) Question 2: Write down the answers supplied from Matlab. Question 3: What is the output from the command: real(ans). 3

7 Output If you get sick of Matlab always repeating everything, you can stop it producing the output of a particular command by ending the line with a ; so >> x=6; assigns the number 6 to x without the usual output. Matlab is also clever enough to recognize integers sometimes: >> cos(pi) ans = -1 But it does not always get it right: Matlab also uses customary scientific notation: >> acos(-1) exp(i pi)/pi ans = 1.0000 + 0.0000i >> cos(1.57) ans = 7.9633e-04 To obtain more significant digits, execute the command: The command >> format long >> cos(1.57) ans = 7.963267107332633e-04 >> format short returns the output format to the default. Matlab lets you know if you screwed up: >> 1/0 Warning: Divide by zero. ans = Inf NOTE: If the warning does not display then enter the command: warning( on, all ) to turn the display of warnings ON. 8 Variables You can create variables in Matlab by assigning numerical values to variable names: >> x=3 assigns the value of 3 to x, and Matlab remembers this until x s value is re-assigned by another command or erased. For example, 4

>> 25 x ans = 7.5 Also, simply typing the variable name produces the value Matlab thinks it has: >> x x = 3 To clear the values assigned to a variable, you can use the command clear. For example, clear x erases the assignment x = 3. Variables can be assigned to the results of computations. For example, >> y=(2+x) 3 y = 125 assigns the value (s + x) 3 = 5 3 = 125 to y. Some variables are already assigned in Matlab: pi stands for π = 3.14159... and i is i = 1. So >> z=2 pi + 6 sqrt(-1) Question 4: What is the answer to the above assignment? 9 Mathematical Functions Matlab has a large number of built-in mathematical functions. Some of these are: abs(x) sqrt(x) sign(x) exp(x) log(x) log10(x) sin(x) cos(x) tan(x) asin(x) acos(x) atan(x) sinh(x) cosh(x) tanh(x) asinh(x) acosh(x) atanh(x) real(z) imag(z) absolute value of x, x square root of x. x sign of x e x ln(x)=log e (x) log 10 (x) sin(x) cos(x) tan(x) sin 1 (x) cos 1 (x) tan 1 (x) sinh(x) cosh(x) tanh(x) sinh 1 (x) cosh 1 (x) tanh 1 (x) Real part of z Imaginary part of z 5

Matlab assumes that the argument is expressed in radians for the trigonometric functions. e.g. >> x=6 x=6 >> z=sin(x)-log(cos(x)) z= -0.2388 computes sin(x) log e (cos(x)) = sin(x) ln(cos(x)) for x = 6. Question #5: Find the absolute value and argument of the complex number, x = z sin(z z ), where z = 2 + i. (Note: The argument is the angle formed by the graph of a complex number on the (Real x Imaginary) axes.) ( ) sinh y sin(x Question #6 Compute the value of the function e 2 ) cosh y cos(x 2 ) 1 at x = 14 and y = ln(3). Question #7: Compute: y = e x [ sin(x) + 28 3x] for x = 12. (a) Check your answer by computing, sin 1 (y exp( x) 28/(3x)) + 4π (b) Why did we put in the 4π? Quit MATLAB by clicking on the File menu in the upper left corner and choosing Exit. Please remember to Log Off (from the Start menu in the lower left of the screen). 6