Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can you implement in java the mid-point rule (integration)?
    primarykey
    data
    text
    <p>Taken from a lab : </p> <blockquote> <p>The aim of this exercise is to implement the midpoint-rule (also called rectangle method) >for the numerical integration of functions.</p> <p>Declare a generic interface Function as follows:</p> <p>public interface Function {B apply(A arg); }</p> <p>Then write a class Maths with a method integrate that implements the midpoint rule for a >function f that is to be integrated between lowerBound and upperBound in n equally-spaced >steps:</p> <p>public static double integrate(Function f, double lowerBound, double upperBound, int n)</p> <p>Test your code by numerical integration ofthe square-function between 0 and 1 (result should be approximately 1.0/3.0)</p> </blockquote> <h2> the sinus-function between 0 and PI/2 (see class java.lang.Math, result should be > approximately 1.0) It seems natural to use named local classes (say "Sinus" and "Square") for this exercise, > but you can also use anonymous local classes if you prefer.</h2> <p>I looked on the wikipedia page but I can't really get my head around the entire concept (especially what is meant by upper and lower bounds). Afaik it's just the way to get the area under a line, given N rectangles used to get the area for each tangential point on the line. I've no idea how to relate it to the above function - recursion maybe? and I've also never seen anything like :</p> <p>B apply(A arg)</p> <p>--</p> <p>So far I've made this progress:</p> <pre><code>public class MidPointRule { public MidPointRule() { } public static double integrate(Function&lt;Double,Double&gt; f, double lowerBound,double upperBound, int n){ double width = upperBound-lowerBound/n; // width is current width-nextwidth/n? return integrate(f,lowerBound,upperBound,n); } public static void main(String[] args) { // sq function between 0 and 1, sinus function between 0 and PI/2. } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload