## Inlab 6: Numerical Integration

Due: Monday 18 July at 6:00 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.

• Create a project called Inlab6.
• Type this code into a Driver and this code into Integration.
• 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 numericallyIntegrate() 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):
1. Why does the solution you wrote work for a generic function?
2. Let lb=1.0, ub=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?
3. Why does Integration not need a constructor?
4. How can I tell in the Driver that numericallyIntegrate() 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.

### Entertainment

This part is not graded at all, but if you want to try to solve a puzzle, see how few lines of code you can add to solve the problem. I do not consider lines with just a bracket "{" to be a line of code. I can do it with one line, but it is super ugly.

### Submission

By Monday afternoon at 6:00 pm, submit the file Integration.java and questions.txt into the appropriate D2L dropbox folder. DO NOT SUBMIT .class files.