I need help urgently.. how to convert this to php?

Discussion in 'Programming' started by hjkca, Dec 3, 2013.

  1. #1
    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):

     
    Last edited by a moderator: Dec 4, 2013
    hjkca, Dec 3, 2013 IP
  2. Ricardo Neves

    Ricardo Neves Greenhorn

    Messages:
    39
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    20
    #2
    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
     
    Ricardo Neves, Dec 4, 2013 IP
    sarahk likes this.
  3. MakZF

    MakZF Well-Known Member

    Messages:
    390
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    140
    #3
    Learn some basic PHP syntax and rewrite it yourself. Your code doesn't do anything too fancy so it shouldn't be too hard.
     
    MakZF, Dec 4, 2013 IP
  4. hjkca

    hjkca Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    Hey thank you so much!
     
    hjkca, Dec 4, 2013 IP