KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums KX Academy question about rank error in function

  • question about rank error in function

    Posted by fav_pa on May 9, 2024 at 12:22 am

    I tried to abstract the Newton-Raphson method in this function, where the user can input a value of c, a first guess x0, and p, the value at which x is raised. However i get a rank error when applying it to for example:
    fbis [2; 1; 3].

    Can someone explain why?

    fbis : {[c_, x0, p_] {[xn ; c; p] xn – ((xn xexp p)-c)%(p * xn xexp p-1)}[; c_; p_]\[x0]}

    Thank you!

    fav_pa replied 6 months, 2 weeks ago 2 Members · 2 Replies
  • 2 Replies
  • rocuinneagain

    Member
    May 9, 2024 at 8:29 am

    , rather than ; separating the arguments of fbis. Otherwise runs fine:

    q)fbis:{[c_;x0;p_]{[xn ;c;p] xn-((xn xexp p)-c)%(p*xn xexp p-1)}[;c_;p_]\[x0]}

    q)fbis[2;1;3]

    1

    1.333333

    1.263889

    1.259933

    1.259921

    1.259921

    • fav_pa

      Member
      May 10, 2024 at 2:36 am

      thank you!
      Silly mistake

Log in to reply.