Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The main objective is to develop a code to numerically integrate functions. More

ID: 3561799 • Letter: T

Question

The main objective is to develop a code to numerically integrate functions. More specifically, this project aims to develop a numerical integration method of a quadratic function defined by:

The program expects input from the user by the way of keyboard.

Start point of the integration (can be positive or negative)

End point of integration (can be positive or negative)

Number of partitions (always a nonzero positive integer)


The output should be directed to the screen.

Left Riemann sum

Right Riemann sum

Specific Requirements:

Your program should contain at least one object named Quadratic

The Quadratic object should contain at least three member variables a, b, and c that define a quadratic function.

The Quadratic object should contain at least one array named xValues of appropriate size that contains the left and right values of the intervals.

The Quadratic object should contain a getter and setter for each of its variables.

The Quadratic object should contain a default constructor that sets a=1, b=2, c=1

The Quadratic object should contain an alternate constructor that sets the values of a, b, and c.

The Quadratic object should contain evaluate method that returns the value of f(x) for any given x.

The Quadratic object should contain leftRiemannSum method that calculates and returns the left sum for the given parameters (start, end, intervals).

The Quadratic object should contain rightRiemannSum method that calculates and returns the right sum for the given parameters (start, end, intervals).

You are free to have more methods and variables.

Help on this would be appreciated.

Explanation / Answer

Program code:

import java.util.Scanner;

public class Integrations

{

    private static double value_a, value_b, value_c;

    public static void main(String[] args)

     {   

          Scanner in = new Scanner(System.in);

          System.out.println("Please enter the values: ");

          System.out.println("Enter value of a: ");

          double a = in.nextDouble();

          System.out.println("Enter value of b: ");

          double b = in.nextDouble();

          System.out.println("Enter value of c: ");

          double c = in.nextDouble();

         

          value_a = a;

          value_b = b;

          value_c = c;

         

          //The Quadratic equation

          System.out.println("Quadratic equation is: " + a + "x^2 + " + b + "x + " + c);

         

          //Prompt the user to enter the start, end and number of interval values

          System.out.println("Enter starting value: ");

          double startValue = in.nextDouble();

          System.out.println("Enter ending value: ");

          double endValue = in.nextDouble();

          System.out.println("Enter number of partitions: ");

          double partition = in.nextDouble();

        

         //Print the output by calling the respective functions

          System.out.println("The Left Riemann sum is: " + LeftRiemannSum(startValue, endValue, partition));

          System.out.println("The Right Riemann sum is: "+ RightRiemannSum(startValue, endValue, partition));        

     }

    //quadraticExpression method that computes the

    //function value at each interval value of x

     public static double quadraticExpression(double value)

     {

          //compute quadratic equation

          double total = (value_a * (value * value) + (value_b * value) + value_c);

          //return the value

          return total;

     }

    

     //RightRiemannSum method that computes the right hand

     //side of the integrations

     public static double RightRiemannSum(double start, double end, double partition)

     {

          double subintervals = end - start;

          double eachsublength = subintervals / partition ;

          double value = start + eachsublength;

          double totalArea = 0;

          for(int x = 0; x < partition; x++){

              totalArea += quadraticExpression(value);

              value = value + eachsublength;

          }

          return totalArea;

     }   

     //LeftRiemannSum method that computes the left hand

     //side of the integrations

     public static double LeftRiemannSum(double start, double end, double partition)

     {        

          double subintervals = end - start;

          double eachsublength = subintervals / partition ;

          double value = start;

          double totalArea = 0;

          for(int x = 0; x < partition; x++)

          {

              totalArea += quadraticExpression(value);

              value = value + eachsublength;

          }

          return totalArea;

     }

}

---------------------------------------------------------------------------------------------------------------------

Sample Output:

Please enter the values:                                                       

Enter value of a:                                                              

3                                                                              

Enter value of b:                                                              

9                                                                              

Enter value of c:                                                              

6                                                                              

Quadratic equation is: 3.0x^2 + 9.0x + 6.0                                     

Enter starting value:                                                          

1                                                                              

Enter ending value:                                                            

5                                                                              

Enter number of partitions:                                                    

5                                                                              

The Left Riemann sum is: 267.6                                                 

The Right Riemann sum is: 375.6                                                

Note:

Program code is in java