<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8" />
<title>k3</title>
<script src="sample.js"></script>
<script src="delta.js"></script>
</head>
<body onload="sample()">
</body>
</html>
var y = new Array();
var x = new Array();
var sol = new Array();
function sample(){
datanumber=100;
numberx = 2;
for (s = 1; s < 101;s++ ){
x[s] = new Array();
}
for (s = 1; s < 101;s++ ){
x[s][1] =1 ;
x[s][2] = s;
y[s] = 5 + 4 * x[s][2] + Math.random();
}
var sub = new ols();
sub.x = x;
sub.y = y;
sub.numberx = 2;
sub.datanumber = 100;
sub.mat();
sol= sub.sol;
alert(sol[1]);
}
class ols{
x:any=new Array();
y:number[]=new Array();
datanumber:number;
numberx:number;
sol:number[]=new Array();
a:any[]=new Array();
b:number[]=new Array();
mat():void{
var s:number;
for(s=1;s<this.numberx+1;s++){
this.a[s]=new Array();
}
var s1:number;
var s2:number;
var d1:number;
for(s1=1;s1<this.numberx+1;s1++){
for(s2=1;s2<this.numberx+1;s2++){
d1=0;
for(s=1;s<this.datanumber+1;s++){
d1=d1+this.x[s][s1]*this.x[s][s2];
}
this.a[s1][s2]=d1;
}}
for(s1=1;s1<this.numberx+1;s1++){
d1=0;
for(s=1;s<this.datanumber+1;s++){
d1=d1+this.x[s][s1]*this.y[s];
}
this.b[s1]=d1;
}
var z:number;
for(s1=1;s1<this.numberx+1;s1++){
for(s2=1;s2<this.numberx+1;s2++){
z=this.a[s2][s1]/this.a[s1][s1];
if(s1==s2)z=0;
for(s=1;s<this.numberx+1;s++){
this.a[s2][s]=this.a[s2][s]-z*this.a[s1][s];
}
this.b[s2]=this.b[s2]-z*this.b[s1]
}
}
for(s=1;s<this.numberx+1;s++){
this.sol[s]=this.b[s]/this.a[s][s];
}
}
}
最終更新:2015年07月24日 13:44