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.
I don't believe them that anyone using threads, at least meaningfully. It's the same thing for Facebook, people just don't engage with Meta platforms like they are thinking. This isn't 2006.
Same
Internet Archive seemed to grab the new version
https://web.archive.org/web/20...d/Setup_MakeMKV_v1.18.4.exe
Here's the link to an additional file it periodically downloads
https://web.archive.org/web/20260213092148/https://www.makemkv.com/sdf.bin
I think update's keys, etc. To manually trigger this update, put the sdf.bin file in the root of where the program is installed. When you launch the program it will pick up the file and import it. Typically put it here: C:\Program Files (x86)\MakeMKV\sdf.bin
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