⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example6_9.java

📁 Java学习丛书科学与工程数值算法(Java版)一书的代码
💻 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 + -