我如何将其转换为PHP? [英] How do i convert this into PHP?
本文介绍了我如何将其转换为PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
静态 void Main()
{
double [] [] pointset = new double [] [] {
new double [] { 10 , 0 。 45 },
< span class =code-keyword> new double [] { 3 。 091 , 12 。 9 },
new double [] { 8 。 12 , 13 。 01 },
new double [] { 6 。 23 , 8 。 731 },
new double [] { 12 。 12 , 2 。 568 },
new < span class =code-keyword> double [] { 9 。 51 ,< span class =code-digit> 5 。 89 },
new double [] { 7 。 67 , 11 。 901 }
};
double [] y = { 0 , 0 };
for ( int i = 0 ; i < 20 ; i ++){
y = algorithm(pointset,y) ;
Console.WriteLine( ({0:0.000},{1:0.000}),y [ 0 ],y [ 1 ]);
}
Console.ReadKey();
}
静态 double []算法( double [] [] pointset, double [] y)
{
double [] s1 = { 0 , 0 };
double s2 = 0 ;
foreach ( double [] point in pointset){
double norm = Eucnorm( new double [] {point [ 0 ] - y [ 0 ], point [ 1 ] - y [ 1 ]});
s1 [ 0 ] + = point [ 0 ] / norm;
s1 [ 1 ] + = point [ 1 ] / norm;
s2 + = 1 / norm;
}
返回 new double [] {s1 [ 0 ] / s2,s1 [ 1 ] / s2};
}
静态 double Eucnorm( double [] v)
{
return Math.Sqrt((v [ 0 ] * v [ 0 ] + v [ 1 ] * v [ 1 ]));
}
解决方案
pointset =数组(
数组(10,0.45),
数组(10,0.45),
数组(3.091,12.9),
数组(8.12,13.01),
数组(6.23,8.731),
数组(12.12,2.568),
数组(9.51,5.89),
数组(7.67) ,11.901)
);
y = array(0,0);
for(
static void Main()
{
double [][] pointset = new double[][]{
new double[] {10,0.45},
new double[] {3.091,12.9},
new double[] {8.12,13.01},
new double[] {6.23,8.731},
new double[] {12.12,2.568},
new double[] {9.51,5.89},
new double[] {7.67,11.901}
};
double[] y = { 0, 0 };
for (int i = 0; i < 20; i++) {
y = algorithm(pointset, y);
Console.WriteLine("({0:0.000},{1:0.000})",y[0],y[1]);
}
Console.ReadKey();
}
static double[] algorithm(double[][] pointset, double[] y)
{
double[] s1 = {0,0};
double s2 = 0;
foreach (double[] point in pointset) {
double norm = Eucnorm(new double[] { point[0] - y[0], point[1] - y[1] });
s1[0] += point[0] / norm;
s1[1] += point[1] / norm;
s2 += 1 / norm;
}
return new double[] {s1[0]/s2, s1[1]/s2};
}
static double Eucnorm(double[] v)
{
return Math.Sqrt((v[0] * v[0] + v[1] * v[1]));
}
解决方案
pointset = array( array(10, 0.45), array(10, 0.45), array(3.091,12.9), array(8.12,13.01), array(6.23,8.731), array(12.12,2.568), array(9.51,5.89), array(7.67,11.901) );
y = array(0,0); for(
这篇关于我如何将其转换为PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文