?? example4_13.java
字號(hào):
import java.applet.*;
import java.awt.*;
public class Example4_13 extends Applet
{
public double F(double[] x)
{int i,n=x.length;
double[] f=new double[n];
double y;
f[0]=3*x[0]+x[1]+2*x[2]*x[2]-3;
f[1]=-3*x[0]+5*x[1]*x[1]+2*x[0]*x[2]-1;
f[2]=25*x[0]*x[1]+20*x[2]+12;
y=0;
for(i=0;i<n;i++)y+=f[i]*f[i];
y=Math.sqrt(y);
return y;
}
public void Mmtcl(double[] x,double b,double eps)
{int i,m,l=0,n=x.length;
double[] x1=new double[n];
double r,y=0,y1=0;
y=F(x);
while(y>eps&&l++<10000)
{ for(m=0;m<1000;m++)
{for(i=0;i<n;i++){r=Math.random()*2*b-b;x1[i]=x[i]+r;}
y1=F(x1);
if(y1<y)break;}
if(m==1000)b/=2;
else
{for(i=0;i<n;i++)x[i]=x1[i];
y=y1;}
}
}
public void paint(Graphics g)
{double[] x={0,0,0};
double[] f=new double[3];
int i,n=x.length;
double b=2,eps=1e-5;
Mmtcl(x,b,eps);
for(i=0;i<n;i++)g.drawString("X"+i+"="+x[i],10,20*i+20);
f[0]=3*x[0]+x[1]+2*x[2]*x[2]-3;
f[1]=-3*x[0]+5*x[1]*x[1]+2*x[0]*x[2]-1;
f[2]=25*x[0]*x[1]+20*x[2]+12;
for(i=0;i<n;i++)g.drawString("f"+i+"="+f[i],10,20*i+80);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -