P31 MATLAB tutorial

# P31 MATLAB tutorial - MATLAB#1 Waves Objectives of the...

This preview shows pages 1–3. Sign up to view the full content.

MATLAB #1 - Waves Objectives of the Lesson: To become familiar with the Matlab working environment, and its syntax. To learn how to plot simple wave-functions. To solve several of the Homework Problems using Matlab. MATLAB Environment, Syntax, and Plotting Simple Function: 1. The Matlab prompt is >>. To enter the Matlab working environment, you will launch the program by clicking on the Matlab icon (if you're using the Macintosh computer), or by opening a shell and typing "Matlab" (if you're using the Unix-based computers). The program will open and display the prompt. 2. Matlab is case sensitive . Stick to lower case for everything!! Otherwise you will make yourself crazy. 3. At the end of every line you type, use the symbol ";" to suppress the display of the values of the function you just typed. Conversely, if you want to see those values, just omit the ";". 4. Enter the following matrix of values for x: >> x=[2:0.1:10]; This entry produces a matrix of values for the variable x ranging from 2 to 10 in intervals of 0.1. 5. Take the sine of x , then create a new variable y equal to the sine of x: >> sin(x); >> y=sin(x); Since x is a matrix, so will y be a matrix. To check on the variables presently stored, and the matrix size of the variables used in your Matlab session, use: >> whos 6. Plot the function y vs. x: >> plot(x,y) 7. To change the value of the variable x, you must retype it, or you can use the mouse to highlight the former x and move it to the present line. On the Macintosh, you must use the copy and paste feature. On UNIX-based workstations, the left mouse button is used to highlight, and the middle mouse button copies the highlighted text to the present location of the cursor. Try:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
>> x=[5:.1:10]; >>y=sin(x); y must be updated, since x was changed >> z=cos(x); >> plot(x,y,'o',x,z,'*') Explain the appearance of your plot. 8. Some special symbols are used for algebraic manipulations. These include "*" for "multiply by"; "^" for "raise to the power"; and "." means "take the elements of the matrix individually". Practice the following: >> y = 2*x; >> plot(x,y) >> y = x.^2; >> plot(x,y) >> y = x/2; >> plot(x,y) Leave off the ";" if you want to see the result of the calculation. 9. Suppose you want to create a 2x2 matrix of values with the first row containing elements 0 5 and the second row containing elements 1 -2. Enter these as: >> z = [0 5 1 -2]; Use the first square bracket on the top line to start entering a matrix. Use the return at the end of each line until you reach the last row of the matrix. Then you must close the square bracket to end the matrix. You may, or may not, add the ";". Try the following to see what effect these operations have upon the matrix z. Leave off the ";" to see the result. Note especially the difference between z.^2 and z^2 >> z1 = z.^2 squares each element of z >> z2 = z*inv(z) matrix times its inverse >> z3 = z^2 matrix z is squared >> z4 = det(z) determinant of z Verify by hand calculations that each of these operations is correct. Which operations rely on the fact
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 10/19/2009 for the course PHY 61 taught by Professor Tobin during the Fall '09 term at Tufts.

### Page1 / 14

P31 MATLAB tutorial - MATLAB#1 Waves Objectives of the...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online