I am trying to write a java program to do the trapezoid rule of the function y = 2.5e^(-x)sin(5x^2.1) + 1.4 for the interval of x = 1 to x = 5. Here is my code:
import java.util.Scanner;
public class Trapezoid
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int n; // number of chunks
final int A = 1; // lower limit
final int B = 5; // upper limit
double area, width, x, areaA, areaB; // area and width of chunks and x = A + width
System.out.print("Enter the number of chunk: ");
n = scan.nextInt();
width = (A + B) / n;
areaA = (width /2) * ((2.5*Math.exp(-A)*Math.sin(5*Math.pow(A, 2.1)) + 1.4));
areaB = (width /2) * ((2.5*Math.exp(-B)*Math.sin(5*Math.pow(B, 2.1)) + 1.4));
area = 0;
for(int i = 1; i < n; i++)
{
x = A + width * i;
area = area + ((width / 2) * (2 * (2.5*Math.exp(-x)*Math.sin(5*Math.pow(x, 2.1)) + 1.4)));
}
area = area + areaA + areaB;
System.out.println("" + area);
}
}
I am trying it with different amounts of trapezoids of 5, 100, and 1000 and when I use 5 it gives me an answer and 100 and 1000 just give 0.0. I think I must be doing something wrong.
Supposedly it's fixed on Series consoles: https://support.forza.net/hc/e...e-Issues-in-Forza-Horizon-6
This game is so much better than FH5, and it's all because of the map. It's diverse, big, and so much to see and do. I've bought every single Forza Motorsport and Horizon game, and by far my least played is FH5 at 100 hours, followed by the latest Motorsport. They've finally made a good one with FH6
Question
M4nB3arP1g
I am trying to write a java program to do the trapezoid rule of the function y = 2.5e^(-x)sin(5x^2.1) + 1.4 for the interval of x = 1 to x = 5. Here is my code:
import java.util.Scanner; public class Trapezoid { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n; // number of chunks final int A = 1; // lower limit final int B = 5; // upper limit double area, width, x, areaA, areaB; // area and width of chunks and x = A + width System.out.print("Enter the number of chunk: "); n = scan.nextInt(); width = (A + B) / n; areaA = (width /2) * ((2.5*Math.exp(-A)*Math.sin(5*Math.pow(A, 2.1)) + 1.4)); areaB = (width /2) * ((2.5*Math.exp(-B)*Math.sin(5*Math.pow(B, 2.1)) + 1.4)); area = 0; for(int i = 1; i < n; i++) { x = A + width * i; area = area + ((width / 2) * (2 * (2.5*Math.exp(-x)*Math.sin(5*Math.pow(x, 2.1)) + 1.4))); } area = area + areaA + areaB; System.out.println("" + area); } }I am trying it with different amounts of trapezoids of 5, 100, and 1000 and when I use 5 it gives me an answer and 100 and 1000 just give 0.0. I think I must be doing something wrong.
Here is the trapezoidal rule: http://en.wikipedia.org/wiki/Trapezoidal_rule
Link to comment
https://www.neowin.net/forum/topic/847972-java-math-problem/Share on other sites
2 answers to this question
Recommended Posts