View Full Document

Matlab



View the full content.
View Full Document
View Full Document

5 views

Unformatted text preview:

Introduction to Matlab Todd Wittman June 16 2008 What is Matlab Matlab Matrix Laboratory is a programming language optimized for linear algebra operations It is very useful for numerical computation and is commonly used by mathematicians After you program in Matlab you probably won t want to go back to C 1 Basic Arithmetic If we type a calculation when we press ENTER the result appears as ans 2 3 ans 5 Pressing the up arrow repeats the last input In addition to basic there are basic mathematical functions exp 2 sin pi asin 2 There may be round off errors Watch out for the values Inf and NaN Variables To assign a value to a variable just type it We don t need to declare variables first x 2 Matlab is weakly typed which means the variable type is flexible x 2 x 2 3 x 2 4i x hello To see what variables are available type who To delete a variable x clear x If you type just clear all variables will be deleted 2 Vectors Matrices We enclose vector values in square brackets v 2 3 4 5 6 We can look up a value at a position v 2 The colon operator takes on a range of values v 2 6 More generally we set start step end default step 1 Ex Make a vector of even integers 2 through 100 evens 2 2 100 Matrices To make a 2D matrix the semi colon skips to the next row A 2 3 4 5 6 7 We look up values by row column A 2 3 7 You can look up sections with the colon A 1 2 2 3 Special matrices rand 10 20 eye 3 zeros 4 5 ones 3 2 As matrices get large you can supress output with a semi colon at the end R rand 20 20 We can display matrix values graphically with imagesc 3 Matrix Operations Matrix multiplication A B A 3 Component wise operations A B A 3 Inverse inv A Transpose A Look up matrix size size A Eignenvalues v d eig A Linear solver Ax b x linsolve A b Vectorize a matrix A Change matrix size reshape A r c Basic Flow Control while i 0 end for i 1 10 end if x 0 elseif x 0 else end 4 Basic Plotting The plot function takes two vectors as input The first goes on the horizontal axis x and the



Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view Matlab and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Matlab and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?