メイン power2.html   Last modified: Sep 01, 2009
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;CHARSET=EUC-JP">
<link rel="shortcut icon" href="../favicon.ico">
<title>JavaScript</title>
<script src="io.js">document.write("io.js ファイルが見つかりません??<br>")</script>

<script language="JavaScript">
<!--

function sp(x, y, n)
{
  var i,  s
  s = 0
  for (i = 0; i < n; i++) {
    s += x[i]*y[i]
  }
  return s
}

function normal(x, n)
{
  var i, s
  s = Math.sqrt(sp(x, x, n))
  for (i = 0; i < n; i++) {
    x[i] /= s
  }
}

function inival(x, n)
{
  var i
  for (i = 0; i < n; i++) {
    x[i] = Math.random()
  }
  normal(x, n)
}

function rat(x, y, arg, n)
{
  var i, q, rmin, rmax
  var eps = 1.0e-20, bignum = 1.0e20
  rmin = bignum
  rmax = -bignum
  for (i = 0; i < n; i++) {
    if (Math.abs(y[i]) < eps) {
      rmin = eps
    }
    else {
      if (Math.abs(x[i]) > eps) {
        q = y[i]/x[i]
        if (q < rmin) {
          rmin = q
        }
        if (q > rmax) {
          rmax = q
        }
      }
      else {
        rmax = bignum
      }
    }
  }
  arg[2] = sp(x, y, n)
  arg[0] = rmin
  arg[1] = rmax
}

function mtxv(a, x, y, n)
{
  var i, j, s
  for (i = 0; i < n; i++) {
    s = 0.0
    for (j = 0; j < n; j++) {
      s += a[j][i]*x[j]
    }
    y[i] = s
  }
}

function pivot(a, b, k, n)
{
  var i, j, imax, g, aik, temp
  g = Math.abs(a[k][k])
  imax = k
  for (i = k+1; i < n; i++) {
    aik = Math.abs(a[i][k])
    if (aik > g) {
      g = aik
      imax = i
    }
  }
  if (imax == k) {
    return
  }
  for (j = k; j < n; j++) {
    temp = a[k][j]
    a[k][j] = a[imax][j]
    a[imax][j] = temp
  }
  temp = b[k]
  b[k] = b[imax]
  b[imax] = temp
}

function gauss(a, b, x, n)
{
  var p, q, s, i, j, k
  var eps = 1.0e-20
  for (k = 0; k < n-1; k++) {
    pivot(a, b, k, n)
    p = a[k][k]
    if (Math.abs(p) < eps) {
      p = eps
    }
    for (j = k; j < n; j++) {
      a[k][j] /= p
    }
    b[k] /= p
    for (i = k+1; i < n; i++) {
      q = a[i][k]
      for (j = k; j < n; j++) {
        a[i][j] -= q*a[k][j]
      }
      b[i] -= q*b[k]
    }
  }
  x[n-1] = b[n-1]/a[n-1][n-1]
  for (k = n-2; k >= 0; --k) {
    s = b[k]
    for (j = k+1; j < n; j++) {
      s -= a[k][j]*x[j]
    }
    x[k] = s
  }
}

function copyv(a, b, n)
{
  var i
  for (i = 0; i < n; i++) {
    b[i] = a[i]
  }
}

function atev(a, qev, x, n)
{
  var i, j, k, y, xx, aa, b, rmax, rmin, rrq, arg
  var eps = 0.0001, kmax = 753
  y = makeVector(n)
  xx = makeVector(n)
  aa = makeMatrix(n, n)
  b = makeVector(n)
  arg = makeVector(3)
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      aa[i][j] = a[j][i]
    }
    aa[i][i] -= qev
    b[i] = -aa[i][n-1]
  }
  gauss(aa, b, x, n-1)
  x[n-1] = 1.0
  normal(x, n)
  for (k = 0; k < kmax; k++) {
    mtxv(a, x, y, n)
    rat(x, y, arg, n)
    rmin = arg[0]
    rmax = arg[1]
    rrq = arg[2]
    copyv(y, x, n)
    normal(x, n)
    if (rmax-rmin <= eps) {
      return
    }
  }
}

function pm(a0, n)
{
  var i, j, k, ban, kai, x, y, z, a, u, v, rmax, rmin, rrq, ev, s, t, evv, vv, arg, m, nagoya
  var eps = 0.0001, kmax = 75
  x = makeVector(n)
  y = makeVector(n)
  z = makeVector(n)
  a = makeMatrix(n, n)
  u = makeVector(n)
  v = makeVector(n)
  evv = makeVector(n)
  vv = makeMatrix(n, n)
  arg = makeVector(n)
  m = n
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) {
      a[i][j] = a0[i][j]
    }
  }
  for (ban = 0; ban < m; ban++) {
    nagoya = 0
    for (kai = 0; kai < 10; kai++) {
      inival(x, n)
      for (k = 0; k < kmax; k++) {
        for (i = 0; i < n; i++) {
          s = 0.0
          for (j = 0; j < n; j++) {
            s += a[i][j]*x[j]
          }
          y[i] = s
        }
        rat(x, y, arg, n)
        rmin = arg[0]
        rmax = arg[1]
        rrq = arg[2]
        if (rmax-rmin <= eps) {
          nagoya = 1
          break
        }
        copyv(y, x, n)
        normal(x, n)
      }
      if (nagoya == 1 ) {
        break
      }
    }
    copyv(y, u, n)
    normal(u, n)
    copyv(u, v, n)
    atev(a, rrq, v, n)
    if (sp(u, v, n) < 0.0) {
      for (i = 0; i < n; i++) {
        v[i] = -v[i]
      }
    }
    s = t = 0.0
    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) {
        s += v[i]*a0[i][j]*u[j]
      }
      t += u[i]*v[i]
    }
    ev = s/t
    evv[ban] = ev
    for (i = 0; i < n; i++) {
      vv[ban][i] = u[i]
    }
    printf("固有値 %17.8g\n", ev)
    printf("固有ベクトル\n")
    for (i = 0; i < n; i++) {
      printf("%15.8g\n", u[i])
    }
    for (i = 0; i < n; i++) {
      for (j = 0; j < n; j++) {
        a[i][j] -= ev*u[i]*v[j]
      }
    }
  }
}

function calc(data_string)
{
  var i, j, nc, rank, r
  if ((r = getdata(data_string, 0)) != false) {
    nc = r.length
    rank = r[0].length
    if (nc != rank) {
      printf("正方行列でなくてはなりません\n")
    }
    else {
      printf("★ 入力された行列 ★\n\n")
      for (i = 0; i < rank; i++) {
        for (j = 0; j < rank; j++) {
          printf("%12.6g", r[i][j])
        }
        printf("\n")
      }

      printf("\n★ 固有値・固有ベクトル ★\n\n")
      pm(r, rank)
    }
  }
  sep2(50)
  printf("\n")
}
//-->
</script>
</head>

<body bgcolor="#ffffff">
<font size="+2"><b>パワー法による固有値・固有ベクトル</b></font> <a  href="src/power.html"><img src="png/src.png" width=35 height=11 alt="src" align=top></a>     Last modified: Jun 01, 2006<hr noshade><p>
<font color="#ff0000" size="+2">以下のプログラムのサポートは終了しました。自己責任でお使い下さい。</font>

<form name=Result>
<script language="JavaScript">
<!--
//-->JavaScript がサポートされていないブラウザですか?
</script>
<input type="button" name="calcurate" value="計算開始" onClick="calc(this.form.data.value)">  
<input type="button" name="clear" value="入力欄クリア" onClick="this.form.data.value=''">  
<input type="button" name="clear" value="出力欄クリア" onClick="this.form.result.value=''"><p>
入力欄(<a href="exa/kugirimoji.html">区切り文字</a>で区切って,行単位に入力)<br><textarea name="data" ROWS=10 COLS=80></textarea><p>
出力欄<br><textarea name="result" ROWS=30 COLS=80></textarea>
</form>

<p><hr noshade>
<img src="../gra/button3.png" width=9 height=9 alt="・"> <a href="../lecture/power-method/power.html">手法の解説</a><br>
<img src="../gra/button3.png" width=9 height=9 alt="・"> <A HREF="javascript:history.go(-1)">直前のページへ戻る</A>  <img src="../gra/button3.png" width=9 height=9 alt="・"> <a href="../mail.html">E-mail to Shigenobu AOKI</a>
<p><center><IMG SRC="../gra/ume5.png" width=121 height=37 ALT="Made with Macintosh"></center>
</body>
</html>

サブ io.js   Last modified: Mar 25, 2004

・ 直前のページへ戻る  ・ E-mail to Shigenobu AOKI

Made with Macintosh