📄 example6_5.java
字号:
import java.applet.*;
import java.awt.*;
public class Example6_5 extends Applet
{
public static double f(double x)
{double y;
y=Math.exp(-x*x);
return y; }
public static double GaussLegendre(double a,double b,int n)
{double s;
double[] y=new double[5];
double[] x=new double[5];
int i;
if(n==0){x[0]=0;y[0]=2;}
else if(n==1){x[0]=-0.5773502692;x[1]=0.5773502692;y[0]=y[1]=1;}
else if(n==2){x[0]=-0.7745966692;x[1]=0;x[2]=0.7745966692;
y[0]=5.0/9;y[1]=8.0/9;y[2]=5.0/9;}
else if(n==3){x[0]=-0.8611363116;x[1]=-0.3399810436;x[2]=0.3399810436;x[3]=0.8611363116;
y[0]=y[3]=0.3478548451;y[1]=y[2]=0.6521451549;}
else if(n==4){x[0]=-0.9061798459;x[1]=-0.5384693101;x[2]=0;x[3]=0.5384693101;x[4]=0.9061798459;
y[0]=y[4]=0.2369268851;y[1]=y[3]=0.4786286705;y[2]=0.5688888889;}
s=0;
for(i=0;i<=n;i++)
{s+=y[i]*f(((b-a)*x[i]+b+a)/2);}
s*=(b-a)/2;
return s;
}
public void paint(Graphics g)
{double y;
int n;
for(n=0;n<=4;n++)
{y=GaussLegendre(1,1.5,n);
g.drawString("I"+n+"="+y,10,20+20*n);
}
}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -