我正在制作一个Java程序来计算Simpson的积分规则.这是我的代码.注意count == 4,9,10,11的输出值中的第二列数字.它们不是我需要的数字,它们不遵循这种模式.我需要这些数字是准确的.发生了什么,我该如何解决?
public static void main(String[] args)
{
double totalS = 0.0;
int count = 0;
for(double i=0; i< 4; i += 0.4 )
{
count++;
totalS += Sfunction(i, count);
System.out.println(count + " " + i + " " + totalS);
}
}
public static double Sfunction(double f1, int count)
{
double value;
if (f1 == 0.0 || f1 == 4.0)
value = Math.cos(Math.sqrt(f1));
else if ((count % 2) == 1)
value = 2 * Math.cos(Math.sqrt(f1));
else
value = …Run Code Online (Sandbox Code Playgroud)