P61 Matlab tutorial

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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
That graph is fine for our present purposes – we’re just trying to make sure the function is what
Background image of page 2
Image of page 3
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 / 4

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online