?? example6_9.java
字號:
import java.applet.*;
import java.awt.*;
public class Example6_9 extends Applet
{
public static double f(double x)
{double y;
y=Math.pow(x,10)+x-1;
return y; }
public static double lianfenshi(double a,double b)
{double[] s=new double[20];
double[] c=new double[20];
double[] h=new double[20];
double y1,y2;
int i,j,n=1;
h[0]=b-a;s[0]=(f(a)+f(b))*h[0]/2;y2=c[0]=s[0];
for(i=1;i<20;i++)
{s[i]=0;
for(j=1;j<=n;j++)s[i]+=f(a+(j-0.5)*h[i-1]);
s[i]*=h[i-1]/2;s[i]+=s[i-1]/2;h[i]=h[i-1]/2;n*=2;
c[i]=s[i];
for(j=0;j<i;j++)c[i]=(h[i]-h[j])/(c[i]-c[j]);
y1=c[i];
for(j=i;j>0;j--){y1=c[j-1]-h[j-1]/y1;}
if(Math.abs(y1-y2)<1e-7)break;
y2=y1;
}
return y2;
}
public void paint(Graphics g)
{double y;
y=lianfenshi(0,1);
g.drawString("積分值為"+y,10,40);}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -