### Create a StudySoup account

#### Be part of our community, it's free to join!

Already have a StudySoup account? Login here

# Class Note for MATH 215 at UA

### View Full Document

## 20

## 0

## Popular in Course

## Popular in Department

This 4 page Class Notes was uploaded by an elite notetaker on Friday February 6, 2015. The Class Notes belongs to a course at University of Arizona taught by a professor in Fall. Since its upload, it has received 20 views.

## Reviews for Class Note for MATH 215 at UA

### What is Karma?

#### Karma is the currency of StudySoup.

#### You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 02/06/15

An Introduction to Matlab Part 4 This lecture assumes that you have already worked through parts 1 3 You should be able to create and use script les create and use vectors and understand the concept of component wise arithmetic This part covers 0 Creating Matrices o Manipulating matrices 0 Matrix addition and multiplication 0 Solving Az b o I sing matrix functions In this part and in future parts we will do a bit less hand holding and let the user attempt to gure how most things themselves Creating matrices This section goes through creating matrices by typing each element using patterns and by using a few built in functions 1 Typing in matriees earplieitly Here we learn how to type matrices a l C 2 Creating a zero matriar ones matriar identity matriar or random matriar Here we disc Open Matlah If you already have it open type clear all in the Command Window Iwould do everything in the Command Window for now so you donquott have to rerun you le everytime we make a change Luckily since you know how to create row and column vectors creating a matrix is easy Recall that putting a space or comma between elements in hracket notation means to change rows Putting a semicolon means to change columns To form a matrix simply combine the two Type A 1 2 3 4 This says the rst row is 1 2 the second row is 3 4 Use this idea to create each of the following 12 34 357amp11g 56791113 001 78 Try typing A 1 2 3 4 5 You get a oerteat vertical concatination error Why Because you tried to make the rst row have onl columns and the second row have 3 columns A matrix must have the same number of columns per row or rows per column how to create a matrix of all zeros all ones completely random entries between 0 and 1 and how to create an identity matrix a l C To create a matrix of all zeros re use the zeros function It takes two for now arguments These represent the size of the matrix you wish to create Type A zeros 54 You get a 5 X 4 zero matrix Try creating a zero matrix of size 10 X 10 To create a matrix of all ones we use the ones function It has the same structure as the zeros function E ones 45 You can create a matrix with random entries these random entries are randomly drawn from between 0 and 1 using the rand function C rand55 d To create an identity matrix we use the function I 55 Manipulating matrices This section tells how to manipulate a given matrix and how to create new matr s from other matrices 1 Changing and adding matrices Here we ll learn how to change parts of a given matrix a 1 2 Eartmct39mg a submat39m39a and combining mat mc Suppose we want to create an elementary matrix of size 5 X 5 that interchanges the rst and last elements So we want the matrix 00001 01000 E00100 00010 10000 We can type in each of the 25 entries of this matrix or we can simply modify the identity matrix or a zero matrix Let us start by modifying the identity matrix to what we want Now we need to change the rst row and the last row We can either change the whole row or just change the needed elements I would change the elements by typing E 11 0 E15 1 E55 0 E51 0 Try to create the E given above by starting with a zero matrix Just like with vectors I can add rows or columns to a given matrix Suppose given the E above we wish to add a row of all zeros turning E into a 6 X 5 matrix Try E6 0 The colon notation in the second index of the matrix means ALL columns So for row 6 and each column of E this assigns a zero We are not restricted to just adding one column or one row Let us take the current E which is 6 X 5 and turn it into a 6 X 7 matrix will all ones in the last two columns We do E6 7 1 Here we extract part of a matrix to create a new matrix and combine two matrices into a larger matrix a 1 We extract elements from a matrix to create a new matri just like with vectors Recall that w h a vector v of size 5 if I wanted a new vector u containing the 15 4 and 5 elements I type a v1 4 5 39We use the same idea for matrices Create A to be a 5 X 5 identity matri 2 Suppose we want to create a matrix B that contains every row of A but only the 15 7 2nd and 4 column We do B Any1 2 4 Try to create a marix C that contains the 15 and 3 rows of A and the 4quot and 5quot columns What matrix do you get 39W an also enlarge a matrix by combining two matrices or a matrix and a vector or even a vector and a vector We again do this the same way as with vectors but we need to be careful about sizes now Create A to be the 5 X 5 identity B to be a random 5 X 4 matrix and C to be a random 4 X 5 matrix Try each of the following A B A B A 0 A 0 B 0 B 0 We nd just like with vectors if we type A B then this adds the matrix B into columns after the matrix A making a 5 X 9 matrix AB attempts to add B as rows after A but A has 5 columns and B only has 4 columns Recall we cannot have a row with a different number of columns than the other rows The same idea holds for each of the other operations We can combine the ideas here with those in c and try 4 Btu3 4 Matrix addition and multiplication Matrix addition and multiplication behave exactly as one would expect The only thing we need to be careful of is that the sizes are correct for the de ned operations 14 Matria addition Here we discuss linear combinations of matrices a Type clear all Create A and B as 3 X 3 random matrices and C as a 3 X 4 random matrix b Compute 2A 7 3B Try to compute A 7 C What happens 2 Matria multiplication Here we discuss matrix matrix multiplication matrix vector multiplication vector matrix mul tiplication and matrix matrix componentwise multiplication a Create two 3 X 3 matri A 1 2 0 2 0 1 1 1 1 and B 1 0 1 0 1 0 2 0 2 b Compute AB by typing A 6 B Compute BA4 Are they the same Should they be c Create a column vector b 1 2 3 and a row vector e 1 2 3 d Compute Ab by typing A b Note that we get a column vector as expected Try to compute Act Why does this not work What should A100 return e Compute CAI Try to compute bA as well f Type A 6 B Type B 6 A Did you get the same thing Why is this so since in part b we showed AB y BA Solving AI b There are multiple w r39s to solve the traditional matrix problem AI b in Matlab We discuss two w 1 We ll use the same A and B from the previous section Recreate them if needed Let b 777 24 Using the inverse of A a We can solve the problem Az b or B1 b l r39 explicitly computing the inverse To do this we use the inn command 1 sign Aino to be the inverse of A by typing Ainiy invA b Now we simply need a matrix vector multiplication z A lb Do this Remember this answer for laterz c Try to compute B l What happens The Inf values mean the matrix has gone to in nity and the Warning Matria is singular to working precision mean the matrix is not invertible it actually means the computer cannot evaluate the inverse but for our purposes they are the same thing 34 Using Gaussian Elimination Prefem ed way to solve Axb easy construct for solving Az b in Matlab It is called the left divide and is denoted by 2 The reason it is called this is because to solve Az b we are essentially dividing the left side of each equation by A In reality when you use left divide Matlab performs Gaussian Elimination with partial pivoting on your linear tem In Matlab this is denoted a A 2b b Try to solve Bz b using Gaussian Elimination Note you get the same error as when you tried lYl L B but now you get a different answer The ran entries mean Not a number Using matrix functions There are many functions which act on matrices4 Most any function that can act on a scalar or vector can also act on a matri 4 Most functions we will simply list and not describe in any detail Use help or doc to nd more information Compute absA s39inA sqrtA and earp Note that each function acts componentwise on the matrix A4 This is important as the matria ayionent ial and a mafria square root have different meanings than componentwise arithmetic they are funtions earpm and sqrtm respectivel 4 Matria transpose To compute the transpose of a given matrix A we use the same construct as computing the transpose 4 T of a vector We use A 4 Compute ATA and ATA l 4 Functions for determining if an invense earists Here we brie y list some functons that can be used in determining if an inverse exists a Use rankA to approximate the rank of A4 b Use c Use d Use e Use inch4 to try to nd the inverse of A4 detA to compute the determinant of A4 rrefA to compute the reduced row echelon form for A4 nuWA to compute the null space of A4 4 As with vectors you can nd the size of a matrix A by typing nm A 4 Later in the class you will want to nd eigenvectors and eigenvalues of a matrix To do this we use the fuction4 It returns two matri 4 The rst contains the eigenvectors as columns and the second is a diagonal matrix that contains the corresponding eigenvalues4 Try W D mm You can extract the eigenvalues as a vector if you would like by typing I draw D Which takes d to be a vector of only the diagonal of D Verify that Avl dlvl where d1 is the rst eigenvalue and U1 is the rst eigenvector4 4 Execute the following commands and try to gure out what each one does to the matrix A minM minM 7rrinnrinz4 sinMA sin14 7 sunMsmMA pr0dA pr0dpr0dA A AN A 0

### BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.

### You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

## Why people love StudySoup

#### "I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

#### "When you're taking detailed notes and trying to help everyone else out in the class, it really helps you learn and understand the material...plus I made $280 on my first study guide!"

#### "Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."

#### "Their 'Elite Notetakers' are making over $1,200/month in sales by creating high quality content that helps their classmates in a time of need."

### Refund Policy

#### STUDYSOUP CANCELLATION POLICY

All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email support@studysoup.com

#### STUDYSOUP REFUND POLICY

StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here: support@studysoup.com

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to support@studysoup.com

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.