Inlab 6: Numerical Integration
Due: Friday 26 February at 6 pm
Purpose
- Use loops to solve a practical problem.
- Refine understanding of Java class structure.
Partners
This is an individual assignment, though collaboration (not
solution sharing) is allowed.
Problem Statement
This is an exciting lab. You will be building an application that
will numerically integrate any function.
Don't panic, you do not need to know calculus to accomplish this
assignment. One of the techniques you will learn in calculus is
how to calculate the area under a curve (graph).
This technique is called integration. This lab will approximate
the integral of a function by adding up various rectangles. An
explanation and example can be found here.
Assignment
- Create a project called Inlab6.
- Paste this code into a Driver and
this code into Calculus.
- You do not need to modify the Driver at any point. Read
through the code and make sure you understand what each part is
supposed to do.
- Add the functionality to integrate() so that the
integration of the function is approximated using rectangles.
- Currently, the function being integrated is x^2, you can
change it to something else if you like.
- When you are done, answer the following questions in a text
document (questions.txt):
- Why does the solution you wrote work for a generic function?
- Let lowerBound=1.0, upperBound=2.0 and change the number of rectangles you
use (10, 100, 1000). If the correct answer should be 7/3, why
does the result become more accurate with more rectangles
used?
- Why does Calculus not need a constructor?
- How can I tell in the Driver that integrate() is
a static method?
Hints
- Do not make this harder than it is. The PDF slides closely
walk through what your code will look like. My solution requires
3 lines of new code, you should not need more than 5-7 to do
this.
- The Driver does not need to be modified.
Submission
By Friday 26 February at 6 pm, submit the file Calculus.java
and questions.txt into the appropriate D2L dropbox folder. DO
NOT SUBMIT .class files.
Grading - 10 points
- 4 points - integrate() works correctly for a
general function and any valid input parameters (lowerBound < upperBound and
numRec > 0).
- 4 points - Questions.
- 2 points - Good programming principles are followed (minimal
unnecessary code, efficient solution,...) and author/version populated correctly