Physics 281 - Computational Physics

Wednesday/Friday Section

Fall 2009

Exercise 3 - Practice with MATLAB Plotting

Practice:

In the command window, generate an array t which contains "times" from 0 to 10 in steps of 0.01.

Now, letting t be the array of times for a calculation of a falling ball, use MATLAB to calculate the position of a ball dropped from a height of 1000m as a function of time using this familiar equation:

z = 1000 - 1/2*g*t^2

Finally, plot z as a function of t using the plot function.

Assignment:

Modify the script you wrote for Exercise 2 to include plotting of the function:

for all times t from 0 to 10 in steps of 0.01, where A0 = 1; g = 9.8; l = 4.

Once again, you must use a for loop to evaluate the value of A for each value in the t array.

HINT: The easiest thing to do is to open your exercise 2 script, make the necessary modification for plotting, and then SAVE the modified script with a new name. Use "plot" function for plotting.

Please write your name in a comment field near the beginning of the script.

Copy your completed program and a jpeg file with the figure containing the plot into the directory ~schloerb/ph281/username, where username is your user name.

The name of the program file and the plot file should be something like exercise3.m and exercise3.jpg, respectively, so that they can be distinguished from other submissions.

See this link for examples of how to copy a file to this directory.

Go to Ph281 Home

Go to Ph281 Topics