📄 integration.java
字号:
import java.math.*;
public class Integration {
public double midpoint(double a,double b)
{
double mf=(b-a)*this.fx((a+b)/2);
return mf;
}
public double trapezoid(double a,double b)
{
double tf=(b-a)/2*(this.fx(a)+this.fx(b));
return tf;
}
public double simpson(double a,double b)
{
double sf=(b-a)/6*(this.fx(a)+this.fx(b)+4*fx((a+b)/2));
return sf;
}
public double fx(double x)
{
x=4/(1+Math.pow(x, 2));
return x;
}
public static void main(String[] args)
{
Integration aaa=new Integration();
//double m=aaa.midpoint(0, 1);
double a=0;
double m=0;
double t=0;
double s=0;
for(int i=0;i<10;i++)
{
double buchang=(double)(1-0)/10;
m=m+aaa.midpoint(a,a+buchang);
t=t+aaa.trapezoid(a,a+buchang);
s=s+aaa.simpson(a,a+buchang);
a=a+buchang;
}
System.out.println(m);
System.out.println(t);
System.out.println(s);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -