Physics 281 - Computational Physics

Wednesday/Friday Section

Fall 2009

Exercise 7 - Numerical Integration

Practice

Write a script to evaluate the following integral using the rectangle rule, trapezoidal rule, and Simpson's rule. The script should also calculate the exact analytical solution of the integration and compare the result to the numerical solution.

Note: these should be your own scripts in which you write the actual integration procedure. Do not use the numerical integration functions that MATLAB provides to do this work.

Assignment

Write a MATLAB script m-file that calls a MATLAB function m-file to evaluate the integrand (function being integrated) in a numerical integration using the trapezoidal integration formula. Our function will be a quadratic as described below:

Your script should allow you to enter:

Your script should write out:

Try your script out on various functions with different step size etc.

Copy your completed program and the function m-file it calls into the directory ~schloerb/ph281/username, where username is your user name. See this link for examples of how to copy a file to this directory.

The name of the main program file should be something like exercise7.m so that it can be distinguished from other submissions. Also give your function m-file a suitable name so that I can identify it.

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

Go to Ph281 Home

Go to Ph281 Topics