Goal
To understand the ideas behind higher-order functions, and use of functions as first-class values in Scheme.
Problem Description
1. A finite sum of a series can be expressed as:
where f is any function, and a and b are integers. Write a general function in Scheme that will return the value of the sum, given parameters f, a and b. Show how your function could calculate the sum of the first n integers, starting at 1, and also the sum of the even squares of the first n integers (e.g. 4,16, 36, etc. )
2. The definite integral of a function f between the limits a and b can be approximated
by the formula:
Write a function in Scheme that will return the value of the integral, given parameters
f, a, b and dx. You must use your function sum
defined in part 1 to help you define this integral function. Show how the function works
by evaluating:
and
Deliverables
The code for your functions, and the appropriate applications of these functions for each example.
Due Date
Wednesday May 3rd., in class.
Notes
There is no need to run these functions through a Scheme interpreter to get full points. However, if you wish, a Scheme interpreter (Solaris only, NOT Linux) is available by typing:
~rth/public/Scheme/scm/scm
The complete definition of the standard version of the language is on the web site at:
http://www.cs.nmsu.edu/~rth/cs/cs471/r4rs.html
A file of Scheme definitions may be loaded by typing (load "filename") at the prompt. Exit the interpreter by typing (quit) at the prompt.