高分悬赏将java算法改为VB算法,下面的程序是java语言写的算法,哪位大虾能将之改为VB语言编写的算法,小妹我将不胜感谢,并一定赠予100分! public static double g(double x,double eps) 
{double[] y=new double[2]; 
double s1,s2,g1,g2,h; 
int i,n=1; 
fun(x,y); 
h=(y[1]-y[0])/2; 
s1=h*(f(x,y[0])+f(x,y[1])); 
s2=s1/2+h*f(x,y[0]+h); 
g1=s2+(s2-s1)/3; 
while(true) 
{h/=2; 
n*=2; 
s1=0; 
for (i=1;i<=n;i++) 
s1+=f(x,y[0]+(2*i-1)*h); 
s1*=h; 
s1+=s2/2; 
g2=s1+(s1-s2)/3; 
if(Math.bas(g2-g1)<eps*(1+Math.abs(g1)))break; 
s2=s1; 
g1=g2; 

return s2; 

public static double simpson2(double a,double b,double eps) 
{ double t1,t2,f1,f2,h; 
int i,n=1; 
h=(b-a)/2; 
t1=h*(g(a,eps)+g(b,eps)); 
t2=t1/2+h*g(a+h,eps)); 
f1=t2+(t2-t1)/3; 
while(true) 
{ h/=2; 
n*=2; 
t1=0; 
for(i=1;i<=n;i++) 
t1+=g(a+(2*i-1)*h,eps); 
t1*=h; 
t1+=t2/2; 
f2=t1+(t1-t2)/3; 
if(Math.abs(f2-f1)<eps*(1+Math.abs(f1)))break; 
t2=t1; 
f1=f2; 

return t2; 
}

解决方案 »

  1.   

    如果按程序字面意思来翻译成VB语法的话就应该是如下:
    Public Static Function g(x As Double, eps As Double) As Double
        Dim y(2) As Double
        Dim s1 As Double, s2 As Double, g1 As Double, g2 As Double, h As Double
        Dim i As Integer, n As Integer
        n = 1
        fun x, y
        h = (y(1) - y(0)) / 2
        s1 = h * (f(x, y(0)) + f(x, y(1)))
        s2 = s1 / 2 + h * f(x, y(0) + h)
        g1 = s2 + (s2 - s1) / 3
        Do
            h = h / 2
            n = n * 2
            s1 = 0
            For i = 1 To n
                s1 = s1 + f(x, y(0) + (2 * i - 1) * h)
            Next
            s1 = s1 * h
            s1 = s1 + s2 / 2
            g2 = s1 + (s1 - s2) / 3
            If Math.bas(g2 - g1) < eps * (1 + Math.Abs(g1)) Then
                Exit Do
            End If
            s2 = s1
            g1 = g2
        Loop
            g = s2
    End FunctionPublic Static Function simpson2(a As Double, b As Double, eps As Double) As Double
        Dim t1 As Double, t2 As Double, f1 As Double, f2 As Double, h As Double
        Dim i As Integer, n As Integer
        n = 1
        h = (b - a) / 2
        t1 = h * (g(a, eps) + g(b, eps))
        t2 = t1 / 2 + h * g(a + h, eps)
        f1 = t2 + (t2 - t1) / 3
        Do
            h = h / 2
            n = n * 2
            t1 = 0
            For i = 1 To n
                t1 = t1 + g(a + (2 * i - 1) * h, eps)
            Next
            t1 = t1 * h
            t1 = t1 + t2 / 2
            f2 = t1 + (t1 - t2) / 3
            If Math.Abs(f2 - f1) < eps * (1 + Math.Abs(f1)) Then
                Exit Do
            End If
            t2 = t1
            f1 = f2
        Loop
        simpson2 = t2
    End Function
      

  2.   

    fun(x,y); 
    ===========此函数在哪定义?
      

  3.   

    if(Math.bas(g2-g1)<eps*(1+Math.abs(g1)))break;
    =========>math.bas 是不是写错了,有这种数学运算吗?