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[IMG]http://www.codeproject.com/script/Forums/Images/smiley_redface.gif[/IMG] .000},{1[IMG]http://www.codeproject.com/script/Forums/Images/smiley_redface.gif[/IMG] .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])); } Code (markup):
Here are some links you might find helpful: http://www.webmonkey.com/2010/02/php_tutorial_for_beginners/ http://www.php.net/manual/en/language.types.array.php http://php.net/manual/en/function.sqrt.php *Important: Forget about declaring a variable as double,float,string, etc on php... just use something like $yourvariable = valuehere
Learn some basic PHP syntax and rewrite it yourself. Your code doesn't do anything too fancy so it shouldn't be too hard.