Question: Write this code in java oriented Consider the cubic function f(1) = r - 13.r +501 - 56. Create a class named Cubic that has
Write this code in java oriented
Consider the cubic function f(1) = r - 13.r +501 - 56. Create a class named Cubic that has a class constant double array with four elements storing the four coefficients of f, that is 1, -13,50, -56. Inside the Cubic class, write a static method that takes a double I parameter to calculate and return the value f(r). Make sure to use the array of coefficients to do your calculations, so that your code is easier to maintain. For a coordinate (a,b), we can calculate the error as the absolute difference between the coordinate and f as b-f(a). Also in the Cubic class, write another static method to calculate and return this error for you. Choose your data types for the parameter and return value appropriately. Create another class named Main, and have it be where your program begins execution. Give it the following class constants: MAX_POINTS = 9 . MIN DOMAIN = 2 MAX_DOMAIN = 7 . MIN_RANGE = -10 MAX_RANGE = 10 Create an ArrayList collection of Point2D elements. Make your collection have MAX POINTS number of coordinates. Make all the r values be chosen from the interval MIN_DOMAIN, MAX_DOMAIN), and make y values chosen from MIN RANGE, MAXRANGE). Look for the Random class in the Java documentation online and search for its nextDouble method, but it will only generate a random double value in the interval [0,1). So, you need to make some calculations to get the bounds needed for r and y. Once you get the above ready, write a static method in the Cubic class that takes a collection of Point2D instances as a parameter, and then returns the total error of all coordinates in the collection against the function f. Finally, call this method in Main and have your output as close as possible to the formatting of the following example (but you will have different numbers each time you run your program): 1-5.4. f(x) - -7.6. - -7.9, Gror - 0.3 - 7.0, f(x) = -0.2. --5.3. orror - 5.1 - 6.6, f(x) = -4.9. - 3.0, error - 7.9 I -4.4. f(x) = -2.6 - -3.9, arror - 1.3 I - 3.9. f(x) = 0.3 Y = -6.6, orror - 6.9 - 2.8. f(x) - 4.0. y - 4.6. error -0.5 I - 6.7f(x) - -3.4. - -4.7. Orror - 1.3 1- 4.0. f(x) - 0.2. y --2.0. GrOr - 2.2 I - 2.9. f(x) - 4.1. y - -1.1, Gror - 5.2 The total error is 30.69 Consider the cubic function f(1) = r - 13.r +501 - 56. Create a class named Cubic that has a class constant double array with four elements storing the four coefficients of f, that is 1, -13,50, -56. Inside the Cubic class, write a static method that takes a double I parameter to calculate and return the value f(r). Make sure to use the array of coefficients to do your calculations, so that your code is easier to maintain. For a coordinate (a,b), we can calculate the error as the absolute difference between the coordinate and f as b-f(a). Also in the Cubic class, write another static method to calculate and return this error for you. Choose your data types for the parameter and return value appropriately. Create another class named Main, and have it be where your program begins execution. Give it the following class constants: MAX_POINTS = 9 . MIN DOMAIN = 2 MAX_DOMAIN = 7 . MIN_RANGE = -10 MAX_RANGE = 10 Create an ArrayList collection of Point2D elements. Make your collection have MAX POINTS number of coordinates. Make all the r values be chosen from the interval MIN_DOMAIN, MAX_DOMAIN), and make y values chosen from MIN RANGE, MAXRANGE). Look for the Random class in the Java documentation online and search for its nextDouble method, but it will only generate a random double value in the interval [0,1). So, you need to make some calculations to get the bounds needed for r and y. Once you get the above ready, write a static method in the Cubic class that takes a collection of Point2D instances as a parameter, and then returns the total error of all coordinates in the collection against the function f. Finally, call this method in Main and have your output as close as possible to the formatting of the following example (but you will have different numbers each time you run your program): 1-5.4. f(x) - -7.6. - -7.9, Gror - 0.3 - 7.0, f(x) = -0.2. --5.3. orror - 5.1 - 6.6, f(x) = -4.9. - 3.0, error - 7.9 I -4.4. f(x) = -2.6 - -3.9, arror - 1.3 I - 3.9. f(x) = 0.3 Y = -6.6, orror - 6.9 - 2.8. f(x) - 4.0. y - 4.6. error -0.5 I - 6.7f(x) - -3.4. - -4.7. Orror - 1.3 1- 4.0. f(x) - 0.2. y --2.0. GrOr - 2.2 I - 2.9. f(x) - 4.1. y - -1.1, Gror - 5.2 The total error is 30.69
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
