AMAT-2120. Fall 2004. Preparation to Final Exam.
Sample programming question 1:
Write a program that calculates the approximate value of the definite integral of the function
f(x)=x^2
using the Rule of Rectangles as given by the formulas below.
The values of a,b (the limits of integration) and N (number of partition points)
should be provided by the user (interactively, in the command line, or through an input file).
> a,b,N; Given
> int(f(x),x=a..b); To approximate the integral
Approximation formula (The Rule of Rectangles)
> (b-a)/N * (sum(f(x[j]), j=1..N-1) +1/2*(f(a)+f(b)));
Here:
> x[j]=a+(b-a)*(j/N);
> f(x):=x^2;