随便啊,用java写的就可以!多谢

解决方案 »

  1.   

    大哥,你怎么不问我啊,我有本《Java常用数值算法集》,专门是介绍算法的,good
      

  2.   

    方法是:解边值问题的松弛法
    方法:
    public class d16r1F
    {
    void sor(double a[][], double b[][], double c[][],
     double d[][], double e[][], double f[][],
     double u[][], int jmax, double rjac)
    {
    int n, j, l;
    double maxits, eps, zero, half, qtr, one, anormf, omega, aaa, bbb;
    double resid, anorm;
            maxits = 1000;
            eps = 0.00001;
            zero = 0.0;
            half = 0.5;
            qtr = 0.25;
            one = 1.0;
            anormf = zero;
            for (j = 2; j <= jmax - 1; j++)
                for (l = 2; l <= jmax - 1; l++)
                    anormf = anormf + Math.abs(f[j][l]);
            omega = one;
            for (n = 1; n <= maxits; n++)
            {
                anorm = zero;
                for (j = 2; j <= jmax - 1; j++)
                {
                    for (l = 2; l <= jmax - 1; l++)
                    {
                        if (((j + l) % 2) ==( n % 2))
                        {
                            aaa = a[j][l] * u[j + 1][l] + b[j][l] * u[j - 1][l];
                            bbb = c[j][l] * u[j][l + 1] + d[j][l] * u[j][l - 1];
                            resid = aaa + bbb + e[j][l] * u[j][l] - f[j][l];
                            anorm = anorm + Math.abs(resid);
                            u[j][l] = u[j][l] - omega * resid / e[j][l];
                        }
                    }
                }
                if (n == 1 )
                    omega = one / (one - half * rjac * rjac);
                else
                    omega = one / (one - qtr * rjac * rjac* omega);
                if ((n > 1) && (anorm < eps * anormf) ) return;
            }
            System.out.println(" maxits exceeded");
            System.exit(1);;
        }
    }
      

  3.   

    例子:
    import java.text.*;
    public class d16r1
    {
    public static void main (String[] args)
    {
    //program d16r1
    //driver for routine sor
    int jmax, i, j, midl;
    double pi, rjac, aaa;
    double a[][] = new double[12][12];
    double b[][] = new double[12][12];
    double c[][] = new double[12][12];
    double d[][] = new double[12][12];
    double e[][] = new double[12][12];
    double f[][] = new double[12][12];
    double u[][] = new double[12][12];
    d16r1F g = new d16r1F();
    DecimalFormat form = new DecimalFormat("0.00");
    jmax = 11;
    pi = 3.1415926;
    for (i = 1; i <= jmax; i++)
    {
                for (j = 1; j <= jmax; j++)
    {
                    a[i][j] = 1.0;
                    b[i][j] = 1.0;
                    c[i][j] = 1.0;
                    d[i][j] = 1.0;
                    e[i][j] = -4.0;
                    f[i][j] = 0.0;
                    u[i][j] = 0.0;
                }
    }
    midl = jmax / 2 + 1;
    f[midl][midl] = 2.0;
    rjac = Math.cos(pi / jmax);
    g.sor(a, b, c, d, e, f, u, jmax, rjac);
    System.out.println();
    System.out.println("sor Solution:");
    System.out.println();
    for (i = 1; i <= jmax; i++)
    {
        for (j = 1; j <= jmax; j++)
                System.out.print(form.format(u[i][j]) + "  ");
        System.out.println();
    }
    System.out.println();
    System.out.println("Test that sulotion satisfies Difference Eqns:");
    System.out.println();
    for (i = 2; i <= jmax - 1; i++)
    {
    for (j = 2; j <= jmax - 1; j++)
    {
    aaa = u[i + 1][j] + u[i - 1][j] + u[i][j + 1] + u[i][j - 1];
    f[i][j] = aaa - 4.0 * u[i][j];
    }
    for (j = 2; j <= jmax - 1; j++)
    System.out.print(form.format(f[i][j]) + "  ");
    System.out.println();
    }
    }
    }
      

  4.   

    运行结果:
    sor Solution:0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  
    0.00  -0.02  -0.04  -0.06  -0.08  -0.09  -0.08  -0.06  -0.04  -0.02  0.00  
    0.00  -0.04  -0.09  -0.13  -0.17  -0.19  -0.17  -0.13  -0.09  -0.04  0.00  
    0.00  -0.06  -0.13  -0.20  -0.28  -0.32  -0.28  -0.20  -0.13  -0.06  0.00  
    0.00  -0.08  -0.17  -0.28  -0.41  -0.55  -0.41  -0.28  -0.17  -0.08  0.00  
    0.00  -0.09  -0.19  -0.32  -0.55  -1.05  -0.55  -0.32  -0.19  -0.09  0.00  
    0.00  -0.08  -0.17  -0.28  -0.41  -0.55  -0.41  -0.28  -0.17  -0.08  0.00  
    0.00  -0.06  -0.13  -0.20  -0.28  -0.32  -0.28  -0.20  -0.13  -0.06  0.00  
    0.00  -0.04  -0.09  -0.13  -0.17  -0.19  -0.17  -0.13  -0.09  -0.04  0.00  
    0.00  -0.02  -0.04  -0.06  -0.08  -0.09  -0.08  -0.06  -0.04  -0.02  0.00  
    0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  Test that sulotion satisfies Difference Eqns:0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  
    0.00  -0.00  0.00  -0.00  0.00  -0.00  0.00  -0.00  0.00  
    0.00  0.00  -0.00  0.00  -0.00  0.00  -0.00  0.00  0.00  
    0.00  -0.00  0.00  -0.00  0.00  -0.00  0.00  -0.00  0.00  
    0.00  0.00  -0.00  0.00  2.00  0.00  -0.00  0.00  0.00  
    0.00  -0.00  0.00  -0.00  0.00  -0.00  0.00  -0.00  0.00  
    0.00  0.00  -0.00  0.00  -0.00  0.00  -0.00  0.00  0.00  
    0.00  -0.00  0.00  -0.00  0.00  -0.00  0.00  -0.00  0.00  
    0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00  0.00
      

  5.   

    看看:
    http://mathforum.org/library/toc.html
    http://www.math.niu.edu/~rusin/known-math/index/35-XX.html#COMP