This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: MIE335S Lab 01 Winter 2012 MIE335 Lab 1 : (Re-)Introduction to MATLAB 1 Overview The purpose of this lab is to refamiliarize yourself with MATLAB fundamentals and features. Read the following tutorial 1 and try all the examples. You can make up numbers if necessary. This outline is broken down into two parts: the first half details using MATLAB (Sections 2 , 3 , 4 ), while the second half details how to program in MATLAB (Section 6 ). 2 Introduction MATLAB ( Mat rix lab oratory) is an interactive software system for numerical computations and graphics. As the name suggests, MATLAB is especially designed for matrix computations: solving systems of linear equations, computing eigenvalues and eigenvectors, factoring matrices, and so forth. In addition, it has a variety of graphical capabilities, and can be extended through programs written in its own programming language. Many such programs come with the system; a number of these extend MATLAB’s capabilities to nonlinear problems, such as the solution of initial value problems for ordinary differential equations. MATLAB is designed to solve problems numerically, that is, in finite-precision arithmetic. Therefore it produces approximate rather than exact solutions, and should not be confused with a symbolic computation system (SCS) such as Mathematica or Maple. It should be understood that this does not make MATLAB better or worse than an SCS; it is a tool designed for different tasks and is therefore not directly comparable. 3 Basics 3.1 Entering vectors and matrices; built-in variables and functions The following commands show how to enter numbers, vectors and matrices, and assign them to variables ( >> is the Matlab prompt) >> a = 2 a = 2 >> x = [1;2;3] x = 1 2 3 >> A = [1 2 3;4 5 6;7 8 9] A = 1 2 3 4 5 6 7 8 9 Notice that the rows of a matrix are separated by semicolons, while the entries on a row are separated by spaces (or commas). 1 Modified from MIE235 and http://www.math.mtu.edu/ msgocken/intro/intro.html 1 MIE335S Lab 01 Winter 2012 A useful command is “ whos ”, which displays the names of all defined variables and their types: >> whos Name Size Bytes Class Attributes A 3x3 72 double a 1x1 8 double x 3x1 24 double Note that each of these three variables is an array; the “shape” of the array determines its exact type. The scalar a is a 1 × 1 array, the vector x is a 1 × 3 array, and A is a 3 × 3 array (see the “size” entry for each variable). You can also find this in the workspace window. One way to enter a n-dimensional array ( n > 2) is to concatenate two or more ( n-1)-dimensional arrays using the cat command. For example, the following command concatenates two 3 × 2 arrays to create a 3 × 2 × 2 array: >> C = cat(3,[1,2;3,4;5,6],[7,8;9,10;11,12]) C(:,:,1) = 1 2 3 4 5 6 C(:,:,2) = 7 8 9 10 11 12 >> whos Name Size Bytes Class Attributes A 3x3 72 double C 3x2x2 96 double a 1x1 8 double x 3x1 24 double Note that the argument “3” in the cat command indicates that the concatenation is to occur along the...
View Full Document
This note was uploaded on 03/31/2012 for the course MIE 335 taught by Professor Frances during the Spring '12 term at University of Toronto.
- Spring '12