Java Reference
In-Depth Information
for the area shown in figure 3.8 .
Figure 3.8. Area under the function f(x) = x + 10 for x from 3 to 7
In this example, the function f is a straight line, and so you can easily work out this area by the
trapezium method (essentially drawing triangles) to discover the solution:
1/2 × ((3 + 10) + (7 + 10)) × (7 - 3) = 60
Now, how might you express this in Java? Your first problem is reconciling the strange notation
like the integration symbol or dy/dx with familiar programming language notation.
Indeed, thinking from first principles you need a method, perhaps called integrate, that takes
three arguments: one is f, and the others are the limits (3.0 and 7.0 here). Thus, you want to
write in Java something that looks like this, where the function f is just passed around:
integrate(f, 3, 7)
 
Search WWH ::




Custom Search