Change picture:

Choose file:

spectral norm

#{
-- The Computer Language Shootout
-- http://shootout.alioth.debian.org/
-- contributed by Isaac Gouy, tuned by Mike Pall
-- modified by Fu Limin for Dao language.
#}


function  Av(n,  x,  y)
{
     for(  i  =  0  :  n-1  ){
          a  =  0.00;
          for(  j  =  0  :  n-1){
               ij  =  i  +  j;
               a  +=  x[j]  /  ((ij*(ij+1))  /  2  +  i+1);
          }
          y[i]  =  a;
     }
}

function  Atv(n,  x,  y)
{
     for(  i  =  0  :  n-1  ){
          a  =  0.00;
          for(  j  =  0  :  n-1){
               ij  =  i  +  j;
               a  +=  x[j]  /  ((ij*(ij+1))  /  2  +  j+1);
          }
          y[i]  =  a;
     }
}

function  AtAv(n,  x,  y,  t)
{
    Av(n,  x,  t);
    Atv(n,  t,  y);
}

function  main(  n  =  100)
{
     u  =  [1.00  :  0  :  n  ];
     v  =  [1.00  :  0  :  n  ];
     t  =  [1.00  :  0  :  n  ];

     for(  i  =  1  :  10){
          AtAv(n,  u,  v,  t);
          AtAv(n,  v,  u,  t);
     }

     vBv,  vv  =  0.00;
     for(  i  =  0  :  n-1  ){
          ui  =  u[i];
          vi  =  v[i];
          vBv  =  vBv  +  ui*vi;
          vv  =  vv  +  vi*vi;
     }
     stdio.printf("%0.9f\n",  math.sqrt(vBv  /  vv));
}

view count 555 times
created at 2009-02-20, 16:33 GMT
modified at 2009-02-22, 23:29 GMT

12 3
456789 10
111213141516 17
181920212223 24
2526272829 30 31

fu: Many thanks (Jul.04,04:29)

klabim: fixed Hi, great, now my test works now :- ). (Jun.30,17:51)

Nightwalker: Few suggestions (Jul.03,14:37)

This site is powered by Dao
Copyright (C) 2009,2010, daovm.net.
Webmaster: admin@daovm.net