Hopefully you all know that the integral of f is the area
under the curve of f, and we define the integral between
a and b as:
When numerically approximating integrals, we cannot make dx->
0, so instead we use very small dx's.
The simplest thing to do is to do just this, and sum up the
dx*f(x) rectangle around a set of discrete points:
a, a+dx, a+2*dx,
... b-dx, b.
This will differ from the real integral as the value of f(x) varies from the f(x) value you use across the distance dx.
As a result, people often consider various approximations which attempt to
do a better job. For example, instead of computing the area of the rectangle
dx*f(x), maybe we should compute the area of the trapezoid from
f(x-dx) to f(dx), assuming that f is
mostly linear between x-dx and x:
A = dx * (f(x-dx)+f(x))/2
Or maybe we should compute the area centered around x, which is more accurate (here we sum up two trapezoids):
A = dx/2 * (f(x-dx/2) + f(x))/2 + dx/2 * (f(x) + f(x+dx/2))/2
= dx/4 * (f(x-dx/2) + 2*f(x) + f(x+dx/2))
Simpson's rule (exercise 1.29 in SICP) is just a variant on this where we use the quadratic expansion:
A = dx/6 * (f(x-dx/2) + 4*f(x) + f(x+dx/2))
When you add up this area across a set of points offset by dx, the -dx/2 term from one point will overlap with the +dx/2 point from the next. This gives us the funny set of alternating 2's and 4's which you saw in exercise 1.29 (and explains why the very end points are weighted by 1 instead of 2).
So, in general, we can define a class of integrators by defining the expansion rule around the discrete points used in the integration. Simpson's rule is one such expansion, the trapezoidal rule is another, and the simple rectangle rule is another.
To provide this generality, the make-integrator function we
ask you to write in (lab 4, partC, 2a) should take in an expansion function
as its first argument. As you see from the assignment, that expansion
function itself takes in two values: x and dx. The
example given in the problem is for Simpson's rule, and you should be able to
see it is just the Scheme translation of the Simpson's rule equation stated
above.
Your make-integrator function should produce an integrator
based on such an expansion function. For part C you will write the expansion
function in Scheme for the simple rectangular expansion rule which was our
first approximation for a discrete integral.
Complex numbers are an extension of the real number system that can handle operations that would be undefined in the real numbers, such as taking the square root of negative numbers. Complex numbers have a great many applications throughout mathematics, science and engineering, and you will undoubtedly encounter them many more times in your education.
A complex number can be represented as a pair of real numbers (x,
y) where x is called the "real part" of the complex
number and y is called the "imaginary part" of the complex
number. They can also be written as x + i * y (or just x
+ iy) where i is the square root of -1. If
you think that -1 doesn't have a square root, that just means
you've been brainwashed by working only with real numbers; it does
have a square root, and we call that number "i", which stands
for "imaginary".
One way to think of complex numbers is as the coordinates of a point in a
two-dimensional plane. So each complex number x + iy
corresponds to a point in the two-dimensional plane with x being
its x-coordinate and y being its y-coordinate. This plane is
usually called the "complex plane".
Another way to represent complex numbers is as a different pair of real
numbers (r, theta). We're still thinking of the complex number
as a point in a two-dimensional plane, but in this case r
(called the "magnitude" of the complex number) represents the distance to the
point from the origin of the two-dimensional plane, whereas
theta (called the "angle" of the complex number) represents the
angle between the x-axis and the line from the origin to the point.
It's important to realize that a single complex number can be represented either using the real/imaginary representation or the magnitude/angle representation. The number is the same in both cases, but the representation is different (think about this for a while; it's a very deep idea that permeates mathematics and science). We can use whatever representation is convenient for the task at hand, and we can convert between representations when it's useful to do so.
Here are some formulas relating the (x, y) representation of
complex numbers to the (r, theta) representation of complex
numbers (x2 means x squared,
sqrt is the square root function and
tan-1 means the arctangent):
x = r * cos(theta)y = r * sin(theta)r = sqrt(x2 + y2)theta = tan-1(y / x)Note that the arctangent function is called atan in Scheme
and has two forms: (atan z) generates the arctangent of a
(possibly complex) number z, while (atan y x)
computes the arctangent of a complex number x + i*y by computing
(atan (/ y x)).
You can add complex numbers by adding their real and imaginary parts:
c1 = x1 + i * y1 c2 = x2 + i * y2 c1 + c2 = (x1 + x2) + i * (y1 + y2)
You can multiply complex numbers by multiplying their magnitudes and adding their angles:
c1 = (r1, theta1) c2 = (r2, theta2) c1 * c2 = (r1 * r2, theta1 + theta2)
Or you can work with the x-y coordinate representation:
c1 = x1 + i * y1 c2 = x2 + i * y2 c1 * c2 = (x1*x2 - y1*y2) + i * (x2*y1 + x1*y2)
You can divide complex numbers by dividing their magnitudes and subtracting their angles:
c1 = (r1, theta1) c2 = (r2, theta2) c1 / c2 = (r1 / r2, theta1 - theta2)
You can also divide complex numbers by working with the x-y coordinates directly (exercise for the reader). You can take the reciprocal of a complex number as follows:
c1 = (r1, theta1) 1/c1 = (1/r1, -theta1)
which follows from the division algorithm. Finally, don't forget the most famous equation relating to complex numbers, Euler's equation:
ei*theta = cos(theta) + i*sin(theta)
where e is the base of natural logarithms e.g.
2.718281828...
That should be enough to get you through this lab. If you want to know more about complex numbers you can look at this page.