- 900 名前:デフォルトの名無しさん [2009/04/16(木) 23:01:38 ]
- <center><script> var x1, y1, x2, y2, x3, y3; var a, b, c, s, S; var S1,S2,M,N;
/*倍率*/ M=100000000; /*回数*/ N=1000; document.write('<style>td,th{font-size:10;}</style><table border=1><tr>'); document.write('<th>x1</th><th>y1</th><th>x2</th><th>y2</th><th>x3</th><th>y3</th>'); document.write('<th>底辺x高さ÷2公式<br>による面積計算結果</th>'); document.write('<th>ヘロン公式による<br>√を使った面積計算結果</th>'); document.write('<th>問題となる誤差<br>倍率'+M+'倍</th></tr>'); for(i=0;N>i;i++){ // 数値を自動代入 x1=(Math.random()*2-1)*M; y1=(Math.random()*2-1)*M; x2=(Math.random()*2-1)*M; y2=(Math.random()*2-1)*M; x3=(Math.random()*2-1)*M; y3=(Math.random()*2-1)*M; a=Math.abs(x1-x2)*Math.abs(y1-y2)/2; // 底辺x高さ÷2公式による面積の計算 b=Math.abs(x2-x3)*Math.abs(y2-y3)/2; c=Math.abs(x3-x1)*Math.abs(y3-y1)/2; s=(Math.max(Math.max(x1,x2),x3)-Math.min(Math.min(x1,x2),x3)) s*=(Math.max(Math.max(y1,y2),y3)-Math.min(Math.min(y1,y2),y3)); S=s-a-b-c; S1=S; a = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); // ヘロン公式による√を使った面積の計算 b = Math.sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2)); c = Math.sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3)); s = (a + b + c) / 2.0; S = Math.sqrt(s * (s - a) * (s - b) * (s - c)); S2=S; document.write('<tr><td> '+x1+'</td><td> '+y1+'</td>'); // 計算結果と誤差を表示 document.write('<td> '+x2+'</td><td> '+y2+'</td><td> '+x3+'</td><td> '+y3+'</td>'); document.write('<td> '+S1+'</td><td> '+S2+'</td><td> '+(S1-S2)+'</td></tr>'); }document.write('</table>'); </script>
|

|