{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

P61 Matlab tutorial

# P61 Matlab tutorial - Matlab tutorial for Physics 61 Lets...

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

Matlab tutorial for Physics 61 Let’s start by working with the states of a one-dimensional infinite square well: elsewhere a x x V = < < = 0 0 ) ( The stationary state wavefunctions (as a function of x ) are: ( ) = a x n a x n π ϕ sin 2 . In order to work with these functions numerically, we need to express them in dimensionless form. The way to do this is to define new, dimensionless variables and functions: ( ) z n x a z f a x z n n π ϕ sin 2 ) ( ) ( = = = Let’s get started. Open Matlab. At the “>>” prompt, you can enter commands. To begin with, we need to define a set of z values. Type the following (including the semicolons): >>dz=0.01; >>z=[0:dz:1]; The equals sign here is used to assign values to a variable. So the first line assigns the value 0.01 to the variable dz. The semicolon tells the program just to accept the command without printing out anything. Try entering the command without the semicolon and see what happens. The second line defines a vector : an array of values that runs from 0 to 1 in increments of dz . So the symbol z represents the entire array of 101 values (0,0.01,0.02, … 0.99,1). MatLab actually treats it as a (1 x 101) matrix – a matrix with a single row and 101 columns. Now let’s define the function f 1 ( z ): >>f1=sqrt(2)*sin(pi*z); 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 0.5 1 1.5 This actually doesn’t define a function , what it does is define an array that contains the values of the function f 1 evaluated at the points defined by the array z . Let’s look at a graph: >>plot(z,f1); MatLab should then open a new window that looks something like this: 1

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

View Full Document
That graph is fine for our present purposes – we’re just trying to make sure the function is what we expect.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern