Last active
August 29, 2015 14:03
-
-
Save aki-lua87/567343fe16a27434c0c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>ヤコビ法</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
</head> | |
<body> | |
<h3>ヤコビ法</h3> | |
<?php | |
if(!$_POST['calc']){ | |
echo '<form action="yakobi.php" method="post">'; | |
echo 'a11<input type="text" name="a11" size="4">a12<input type="text" name="a12" size="4">a13<input type="text" name="a13" size="4">b1<input type="text" name="b1" size="4"><br/>'; | |
echo 'a21<input type="text" name="a21" size="4">a22<input type="text" name="a22" size="4">a23<input type="text" name="a23" size="4">b2<input type="text" name="b2" size="4"><br/>'; | |
echo 'a31<input type="text" name="a31" size="4">a32<input type="text" name="a32" size="4">a33<input type="text" name="a33" size="4">b3<input type="text" name="b3" size="4"><br/><br/>'; | |
echo "<br/>"; | |
echo '反復回数<input type="text" name="k" size="4"/><br/>'; | |
echo '初期値<input type="text" name="s" size="4"/><br/>'; | |
echo '<br/><input type="submit" name="calc" value="送信">'; | |
echo '</form>'; | |
} | |
else | |
{ | |
/*a*/ | |
$a11 =$_POST['a11']; | |
$a12 =$_POST['a12']; | |
$a13 =$_POST['a13']; | |
$a21 =$_POST['a21']; | |
$a22 =$_POST['a22']; | |
$a23 =$_POST['a23']; | |
$a31 =$_POST['a31']; | |
$a32 =$_POST['a32']; | |
$a33 =$_POST['a33']; | |
/*b*/ | |
$b1 =$_POST['b1']; | |
$b2 =$_POST['b2']; | |
$b3 =$_POST['b3']; | |
/*反復回数k 初期値s*/ | |
$k = $_POST['k']; | |
$s = $_POST['s']; | |
$x1[0] = $x2[0] = $x3[0] = number_format($s,7); /* 初期値*/ | |
/*偏差ナシ*/ | |
$e1[0] = "-"; | |
$e2[0] = "-"; | |
$e3[0] = "-"; | |
for($i = 1; $i <= $k; $i = $i + 1) | |
{ | |
/*ヤコビ法計算*/ | |
$x1[$i] = ($b1 - $a12*$x2[$i-1] - $a13*$x3[$i-1])/$a11; | |
$x2[$i] = ($b2 - $a21*$x1[$i-1] - $a23*$x3[$i-1])/$a22; | |
$x3[$i] = ($b3 - $a31*$x1[$i-1] - $a32*$x2[$i-1])/$a33; | |
/*四捨五入*/ | |
$x1[$i] = round($x1[$i],7); | |
$x2[$i] = round($x2[$i],7); | |
$x3[$i] = round($x3[$i],7); | |
/*桁揃え*/ | |
$x1[$i] = number_format($x1[$i],7); | |
$x2[$i] = number_format($x2[$i],7); | |
$x3[$i] = number_format($x3[$i],7); | |
/*偏差量計算*/ | |
$e1[$i] = $x1[$i] - $x1[$i-1]; | |
$e2[$i] = $x2[$i] - $x2[$i-1]; | |
$e3[$i] = $x3[$i] - $x3[$i-1]; | |
/*絶対値*/ | |
$e1[$i] = abs($e1[$i]); | |
$e2[$i] = abs($e2[$i]); | |
$e3[$i] = abs($e3[$i]); | |
/*四捨五入*/ | |
$e1[$i] = round($e1[$i],7); | |
$e2[$i] = round($e2[$i],7); | |
$e3[$i] = round($e3[$i],7); | |
/*桁揃え*/ | |
$e1[$i] = number_format($e1[$i],7); | |
$e2[$i] = number_format($e2[$i],7); | |
$e3[$i] = number_format($e3[$i],7); | |
} | |
/* 結果の出力 */ | |
echo "<table border = 1>"; | |
echo "<tr><th>反復回数k</th><th>x1</th><th>ε1</th><th>x2</th><th>ε2</th><th>x3</th><th>ε3</th></tr>"; | |
for($i = 0;$i <= $k; $i = $i +1) | |
{ | |
echo "<tr><th> ".$i."</th><th> ".$x1[$i]."</th><th> ".$e1[$i]."</th><th> ".$x2[$i]."</th><th> ".$e2[$i]."</th><th> ".$x3[$i]."</th><th> ".$e3[$i]."</th></tr>"; | |
} | |
echo "</table>"; | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment