Your job in this project: write programs to
You may not use MATLAB's built-in functions for finding maxima or performing numerical integration -- instead, please implement these algorithms yourself.
You'll need to modify one of your existing MATLAB source code files this week, plus write three more. Don't worry -- they are all very much alike, and you'll be able to cut and paste.
function energy = planck_integ(start_lambda, end_lambda, temperature, epsilon)
This week, I want you to consider a single case (the Sun, over the visible range of wavelengths):
Set epsilon = 1e-6, as before.
Questions:
# of slices fractional change since previous iteration ---------------------------------------------------------- 2 4 8 16 32
Now, with the experience you've gained so far, it should be easy to write a program which integrates an arbitrary function of one variable, instead of the Planck function. The user will pass the name of the function to your program, which will then evaluate it over a given interval.
In fact, write three programs:
function integ = rect_integ(start_x, end_x, func, epsilon) function integ = trap_integ(start_x, end_x, func, epsilon) function integ = simpson_integ(start_x, end_x, func, epsilon)in which
start_x is the starting point of the interval over which to integrate end_x is the ending point of the interval over which to integrate func is the name of a function to integrate epsilon denotes the termination criterion: keep going until the fractional change in the integral drops to this level integ (the output argument) is the result of the integration
For example, I might integrate sine(x) over the interval x=0 to x=10 by calling
a = rect_integ(0, 10, 'sin', 1e-6);or I might integrate a simple little function stored in file simple.m like this:
function y = simple(x) y = sin(100*x)*exp(-x);by calling
a = rect_integ(0, 10, 'simple', 1e-6);
I suggest that you test your functions by using them to integrate simple functions, to which you know the correct answer.
Use each of your functions to integrate tan(x) over the interval x=0.1 to x=1.4, where "x" is in radians (this is how MATLAB does all its trigonometry). Make a table which shows
Make a graph which shows the fractional change on the x-axis, and the time required to find the integral to that precision on the y-axis. Use logarithmic axes in both directions. Plot the points for each method together on the same graph, so that you can compare the methods directly. What does the graph tell you about the efficiency of the different methods?
Bells and Whistles
y = sin(100*x) * exp(-x)(where the argument of sin is in radians, as usual) over the range from 0 to 10. Calculate the answer analytically and compare to your numerical method. How many pieces do you need to get an accurate result? Why is this function so hard to integrate?
This page maintained by Michael Richmond. Last modified Apr 16, 2003.
Copyright © Michael Richmond. This work is licensed under a Creative Commons License.