除了vector(1,n)不是很清楚你干了些什么以外,
我想这段代码几乎就可以在Java中编译了,因为你没有用到什么指针(float *g,*h;只要替换成float[]g;float[] h就基本上可以了。

解决方案 »

  1.   

    gp!
    什么作业?! 我在编程的时候还没有Java呢!
      

  2.   

    不一定对:public class Toeplz
    {
    public float[] toeplz(float r[], float y[], int n)
    //Solves the Toeplitz system PN
    //j=1 R(N+i.j)xj = yi (i = 1; : : :;N). The Toeplitz matrix need
    //not be symmetric. y[1..n] and r[1..2*n-1] are input arrays; x[1..n] is the output array.
    {
    int j,k,m,m1,m2;
    float pp,pt1,pt2,qq,qt1,qt2,sd,sgd,sgn,shn,sxn;
    float[] x,g,h;
    if (r[n] == 0.0) 
    {
    System.out.println("toeplz-1 singular principal minor");
    return null;
    }

    x=new float[n];
    g=new float[n];
    h=new float[n];
    x[0]=y[0]/r[n-1]; //Initialize for the recursion.
    if (n == 1) return x;
    g[0]=r[n-2]/r[n-1];
    h[0]=r[n]/r[n-1];

    boolean flag = false;
    for (m=0;m<n;m++) { //Main loop over the recursion.
    m1=m+1;
    sxn = -y[m1]; //Compute numerator and denominator for x,
    sd = -r[n-1];
    for (j=0;j<=m;j++) {
    sxn += r[n-1+m1-j]*x[j];
    sd += r[n-1+m1-j]*g[m-j+1];
    }
    if (sd == 0.0) 
    {
    System.out.println("toeplz-2 singular principal minor");
    break;
    }
    x[m1]=sxn/sd; //whence x.

    for (j=0;j<=m;j++) x[j] -= x[m1]*g[m-j+1];

    if (m1 == n-1) 
    {
    flag = true;
    break;
    }

    sgn = -r[n-1-m1]; //Compute numerator and denominator for G and H,
    shn = -r[n-1+m1];
    sgd = -r[n-1];
    for (j=0;j<=m;j++) {
    sgn += r[n-1+j-m1]*g[j];
    shn += r[n-1+m1-j]*h[j];
    sgd += r[n-1+j-m1]*h[m-j+1];
    }
    if (sd == 0.0 || sgd == 0.0) 
    {
    System.out.println("toeplz-3 singular principal minor");
    break;
    }

    g[m1]=sgn/sgd; //whence G and H.
    h[m1]=shn/sd;
    k=m;
    m2=(m+1) >> 1;
    pp=g[m1];
    qq=h[m1];
    for (j=0;j<=m2;j++) {
    pt1=g[j];
    pt2=g[k];
    qt1=h[j];
    qt2=h[k];
    g[j]=pt1-pp*qt2;
    g[k]=pt2-pp*qt1;
    h[j]=qt1-qq*pt2;
    h[k--]=qt2-qq*pt1;
    }
    } //Back for another recurrence.
    if(flag) return x;
    else
    {
    System.out.println("toeplz - should not arrive here!");
    return null;
    }
    }
    }
      

  3.   

    肯定对
    public class Toeplz
    {
    public float[] toeplz(float r[], float y[], int n)
    //Solves the Toeplitz system PN
    //j=1 R(N+i.j)xj = yi (i = 1; : : :;N). The Toeplitz matrix need
    //not be symmetric. y[1..n] and r[1..2*n-1] are input arrays; x[1..n] is the output array.
    {
    int j,k,m,m1,m2;
    float pp,pt1,pt2,qq,qt1,qt2,sd,sgd,sgn,shn,sxn;
    float[] x,g,h;
    if (r[n] == 0.0) 
    {
    System.out.println("toeplz-1 singular principal minor");
    return null;
    }

    x=new float[n];
    g=new float[n];
    h=new float[n];
    x[0]=y[0]/r[n-1]; //Initialize for the recursion.
    if (n == 1) return x;
    g[0]=r[n-2]/r[n-1];
    h[0]=r[n]/r[n-1];

    boolean flag = false;
    for (m=0;m<n;m++) { //Main loop over the recursion.
    m1=m+1;
    sxn = -y[m1]; //Compute numerator and denominator for x,
    sd = -r[n-1];
    for (j=0;j<=m;j++) {
    sxn += r[n-1+m1-j]*x[j];
    sd += r[n-1+m1-j]*g[m-j+1];
    }
    if (sd == 0.0) 
    {
    System.out.println("toeplz-2 singular principal minor");
    break;
    }
    x[m1]=sxn/sd; //whence x.

    for (j=0;j<=m;j++) x[j] -= x[m1]*g[m-j+1];

    if (m1 == n-1) 
    {
    flag = true;
    break;
    }

    sgn = -r[n-1-m1]; //Compute numerator and denominator for G and H,
    shn = -r[n-1+m1];
    sgd = -r[n-1];
    for (j=0;j<=m;j++) {
    sgn += r[n-1+j-m1]*g[j];
    shn += r[n-1+m1-j]*h[j];
    sgd += r[n-1+j-m1]*h[m-j+1];
    }
    if (sd == 0.0 || sgd == 0.0) 
    {
    System.out.println("toeplz-3 singular principal minor");
    break;
    }

    g[m1]=sgn/sgd; //whence G and H.
    h[m1]=shn/sd;
    k=m;
    m2=(m+1) >> 1;
    pp=g[m1];
    qq=h[m1];
    for (j=0;j<=m2;j++) {
    pt1=g[j];
    pt2=g[k];
    qt1=h[j];
    qt2=h[k];
    g[j]=pt1-pp*qt2;
    g[k]=pt2-pp*qt1;
    h[j]=qt1-qq*pt2;
    h[k--]=qt2-qq*pt1;
    }
    } //Back for another recurrence.
    if(flag) return x;
    else
    {
    System.out.println("toeplz - should not arrive here!");
    return null;
    }
    }
    }
      

  4.   

    这是我的测试程序:
    public class Toeplz
    {
    public static void main(String[] args)
    {
    double[] r = new double[]
    { 1,2,3,4,5,6,7,8 };
    double[] y = new double[]
    {
                7,5,12,2,24,14,13,5
    };
    double[] x = Toeplz.toeplz(r,y,r.length-1);
    for ( int i=0; i<x.length;i++ )
    {
    System.out.println("a["+i+"]="+x[i]);
    } }
        public static double[] toeplz(double r[], double y[], int n)
        //Solves the Toeplitz system PN
        //j=1 R(N+i.j)xj = yi (i = 1; : : :;N). The Toeplitz matrix need
        //not be symmetric. y[1..n] and r[1..2*n-1] are input arrays; x[1..n] is the output array.
        {
            int j,k,m,m1,m2;
            double pp,pt1,pt2,qq,qt1,qt2,sd,sgd,sgn,shn,sxn;
            double[] x,g,h;
            if (r[n] == 0.0)
            {
                System.out.println("toeplz-1 singular principal minor");
                return null;
            }        x=new double[n];
            g=new double[n];
            h=new double[n];
            x[0]=y[0]/r[n-1]; //Initialize for the recursion.
            if (n == 1) return x;
            g[0]=r[n-2]/r[n-1];
            h[0]=r[n]/r[n-1];        boolean flag = false;
            for (m=0;m<n;m++) { //Main loop over the recursion.
                m1=m+1;
                sxn = -y[m1]; //Compute numerator and denominator for x,
                sd = -r[n-1];
                for (j=0;j<=m;j++) {
                    sxn += r[n-1+m1-j]*x[j];
                    sd += r[n-1+m1-j]*g[m-j+1];
                }
                if (sd == 0.0)
                {
                    System.out.println("toeplz-2 singular principal minor");
                    break;
                }
                x[m1]=sxn/sd; //whence x.            for (j=0;j<=m;j++) x[j] -= x[m1]*g[m-j+1];            if (m1 == n-1)
                {
                    flag = true;
                    break;
                }            sgn = -r[n-1-m1]; //Compute numerator and denominator for G and H,
                shn = -r[n-1+m1];
                sgd = -r[n-1];
                for (j=0;j<=m;j++) {
                    sgn += r[n-1+j-m1]*g[j];
                    shn += r[n-1+m1-j]*h[j];
                    sgd += r[n-1+j-m1]*h[m-j+1];
                }
                if (sd == 0.0 || sgd == 0.0)
                {
                    System.out.println("toeplz-3 singular principal minor");
                    break;
                }            g[m1]=sgn/sgd; //whence G and H.
                h[m1]=shn/sd;
                k=m;
                m2=(m+1) >> 1;
                pp=g[m1];
                qq=h[m1];
                for (j=0;j<=m2;j++) {
                    pt1=g[j];
                    pt2=g[k];
                    qt1=h[j];
                    qt2=h[k];
                    g[j]=pt1-pp*qt2;
                    g[k]=pt2-pp*qt1;
                    h[j]=qt1-qq*pt2;
                    h[k--]=qt2-qq*pt1;
                }
            } //Back for another recurrence.
            if(flag) return x;
            else
            {
                System.out.println("toeplz - should not arrive here!");
                return null;
            }
        }
    }出现以下错误:
    java.lang.ArrayIndexOutOfBoundsException
    at Toeplz.toeplz(Toeplz.java:48)
    at Toeplz.main(Toeplz.java:13)
    Exception in thread "main"
      

  5.   

    在原程序中
    x=new double[n];
    g=new double[n];
    h=new double[n];
    的大小是从1-n,而不是从0-(n-1),
      

  6.   

    看C的算法
    sxn += r[n+m1-j]*x[j];
    n应该小于r.length/2
      

  7.   

    我编过一个这样的java applet 多元一次方程组 要得话 [email protected]