New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

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

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here


by: Claudine Friesen


Claudine Friesen
GPA 3.56


Almost Ready


These notes were just uploaded, and will be ready to view shortly.

Purchase these notes here, or revisit this page.

Either way, we'll remind you when they're ready :)

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

Class Notes
25 ?




Popular in Course

Popular in Mathematics (M)

This 8 page Class Notes was uploaded by Claudine Friesen on Monday September 28, 2015. The Class Notes belongs to MATH313 at University of Pennsylvania taught by Staff in Fall. Since its upload, it has received 45 views. For similar materials see /class/215404/math313-university-of-pennsylvania in Mathematics (M) at University of Pennsylvania.

Similar to MATH313 at Penn

Popular in Mathematics (M)




Report this Material


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: 09/28/15
Introduction to Matlab for Math 313 What does Matlab do Matlab is very powerful math computation software Matlab can solve very complicated systems of equations plot 3D images and much more Matlab is one of the best programs for working with matricesvectors and for writing simple programs that do very difficult math computations For this class we will be working a lot with matrices and operations on matrices hence Matlab will be a very useful tool What you see After opening Matlab we see three windows The main window on the left is called the Command Window and this is where math operations function calls variable creation and much more can be done The window in the upper left is your Current Directory or Workspace depending on which tab at the bottom of this window is selected The Current Directory is usually the work subfolder contained in the Matlab folder and it shows what your work directory contains such as data files Mflles and figure files The Workspace lists all your current objectsvariables that have been created The last window on the bottom left is the Command History Window This window remembers all the commands that you have typed into the Command Window How do you use Matlab The best way to learn Matlab is to use it Let s start with something simple Type help ltc0mmandgt at the Matlab command prompt to see useful information about certain Matlab commands EDUgtgt help zeros ZEROS Zeros array ZEROSN is an N by N matrix of zeros ZEROSMN or ZEROSMN is an M by N matrix of zeros ZEROSMNP or ZEROSM N P is an M by N by P by array of zeros ZEROSSIZEA is the same size as A and all zeros ZEROS with no arguments is the scalar 0 ZEROSMNCLASSNAME or ZEROSMNCLASSNAME is an M by N by array of zeros of class CLASSNAME Example x zeros2339int839 See also eye ones Let s make a simple row vector We use with numbers separated by spaces or commas to distinguish entries in a row EDUgtgtX 123 X 1 2 3 To make a column vector we separate the entries by semicolons We also can use a semicolon at the end of a statement to suppress output EDUgtgt Y 345 EDUgtgt Y Y 3 4 5 Now let s make a 2x3 matrix EDUgtgtZ 123345 Z 1 2 3 3 4 5 We can transpose a matrix or a vector using 39 The transpose of an m x n matrix A is the n x m matrix A whose rows are the columns of A and whose columns are the rows of A EDUgtgt Y39 ans 3 4 5 We could have built the matrix Z by using the row vector X and the transpose of the column vector Y as follows EDUgtgt XY39 ans 1 2 3 3 4 5 There are more efficient ways to produce vectors To learn these one must experiment and read through the help documentation found under the help drop listgtMATLAB help or by pressing F1 In most help file entries there is a line or two of sample commands to show you how to do things The following abc command says make a row vector starting at value a and each following entry is b greater until we reach or pass the value c EDUgtgtW 115 w 12345 Now lets make a matrix using the zeros command which we got help information on earlier EDUgtgt M zer0s3 M 0 0 0 0 0 0 0 0 0 Other useful matrix creation commands are eye diag and ones We can edit a speci c entry of M by indexing it EDUgtgt M111 M221 M331 M M 1 0 0 0 1 0 0 0 1 The size command is useful to get a matrix or vector size when one is unknown EDUgtgt sizeX ans 1 3 EDUgtgt sizeM ans 3 3 But when is the size of a matrix or vector unknown to you Well Matlab allows you to write simple programs that take arguments in the form of matrices vectors and other things like strings such as a file name You may want to write a program which takes any size matrix and swaps the last two rows To do this we need to make an Mfile To make an M le go to legtnewgtM le or click the little piece of paper in the upper left hand comer Now we need to name our programfunction label our output and label any variable inputs If we need to add a comment in our code we use the symbol See the sample M le code for swapping the last two rows of a matrix Swapm function s swapN This function swaps that last two rows of input matrix N If irput matrix N has only one row then we do nothing First we need to get the number of roows of N rows columns sizeN Let39s assign our output and then manipulate it s N Now we check if it has at least two rows if rows gt 1 If we are here then N has more then 1 row so we swap the last two Let39s save the last and second to last rows lastRow srows secondLastRow srows l Now replace the last two rows in N srows secondLastRow srows l lastRow end the if statement end our output will be s which is N but with the last two rows now swapped Any command above that you do not know try it in the command window on your own to see what is does Let s see if swap works EDUgtgt swapM ans an ace GHQ If we want to save our output to a le we create what is called a diary le The following code produces a text le of our output EDUgtgt diary sampletxt EDUgtgt N diag1 2 3 4 5 N 1 0 0 0 0 0 2 0 0 0 0 0 3 0 0 0 0 0 4 0 0 0 0 0 5 EDUgtgt swapN ans 1 0 0 0 0 0 2 0 0 0 0 0 3 0 0 0 0 0 0 5 0 0 0 4 0 EDUgtgt diary off EDUgtgt And the text le sampletXt now contains N diag1 2 3 4 5 N 1 0 0 0 0 0 2 0 0 0 0 0 3 0 0 0 0 0 4 0 0 0 0 0 5 swapN ans 1 0 0 0 0 0 2 0 0 0 0 0 3 0 0 0 0 0 0 5 0 0 0 4 0 diary off Matlab can do a lot more too We can write programs that use for loops or while loops We can add subtract and multiply matrices and vectors and much more Helpful web references http wwwmathworks com ac ademia studenticentertutorials launchp ad html http wwwmathu eduhelpmatlabtutorial Your assignment 1 Create the following matrices H 5 0 0 0 5 0 0 0 5 K 1 2 3 4 5 6 L 1 4 2 5 3 6 2 Compute G KHL 3 Compute J GAl The inverse of an n x n matrix A if it exists is the n x n matrix A391 with A A391 1 Compute GJ and JG Compute K L What happens if you try to compute K L Write an Mflle that uses a for loop with function and le name even le will be evenm and the function name will be evenn that prints the even numbers between 1 and n where n is a positive integer input you do not need to check that n is a positive integer Use help to see how to use a for loop 7 Test your Mflle with n 10 and 11 994 Record all your output problems l23457 in a dairy flle labeled youmameltxt example WilBradyltxt Turn in a printout of your dairy file and a printout of your M file You should staple everything together and leave it in the top box on the door outside 4Cl3 Please be sure that your name is on everything you hand in This assignment is due by 4pm on Thursday February 2 and forms a part of Homework Set 3


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

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

Jim McGreen Ohio University

"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."

Anthony Lee UC Santa Barbara

"I bought an awesome study guide, which helped me get an A in my Math 34B class this quarter!"

Steve Martinelli UC Los Angeles

"There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."


"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."

Become an Elite Notetaker and start selling your notes online!

Refund 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


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:

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

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.