Beta

Newton's Method

Description
Loading description...
Algorithms
  • Please sign in or sign up to leave a comment.
  • cemsina Avatar

    This comment has been hidden.

  • user6800471 Avatar

    could you implement a algo which solve not only poly equation, and non-linear equations?

  • Unnamed Avatar

    This comment has been hidden.

  • readerboy7 Avatar

    My solution passes every fixed test case. However, it infrequently fails on random tests, due to some minor differences in behaviour with out implementations (you round to 13 dp every iteraton, I don't. Rounding to 13 dp is not mentioned in the description). These random tests are infrequent enough that I can get luckly and get test cases with no errors if I attempt a few times.

    This seems to be because in those cases either

    a) my algorithm finds a solution, yours doesn't.

    b) my algorithm finds a different solution than yours.

    Neither of those should result in failed tests

    My suggestion:

    If the returned result doesn't match yours, also have the code check if it's a valid solution (even if it's different from yours), instead of rejecting it.

  • uttumuttu Avatar

    The convergence criteria should be written out in the description, because otherwise consistently arriving to the expected solution is nigh impossible.

    For example, if I increase the maximum number of iterations too much, I keep finding solutions for which your reference solution expects a None. Conversely, if I tighten convergence rules (e.g., on |x_{n+1} - x_n| or f(x)) too much, I don't find solutions.

  • user6800471 Avatar

    if derivative of f equal zero, what happens them. Right, division by zero, then you should add tests which return a "nothing" result.

    For example

    "x^2 + x + 2" -> "nothing"
    'x^4 + 2x^2 + 3" -> "nothing"
     '3' -> nothing
    
  • uttumuttu Avatar

    Without disabling numpy, this is a far cry from the estimated 2 kyu rank.

  • Mercy Madmask Avatar

    You called your tests random but it's always the same ones.

  • Mercy Madmask Avatar

    Your solution doesn't seem perfect:

    2x^11-87x^10+72x^9+88x^8-42x^7+96x^6+38x^5-70x^4-22x^3-30x^2-33x-90
    {1.55065, 42.6316, 1.1071} should equal [1.55065, 1.1071]
    

    You can see 42.6316 is a solution if you plot the equation (with google for example).

  • Rud1 Avatar

    [-1.1231, 0.82568, 1.25037] should equal [0.82568, 1.25037, -1.1231]
    The solution beeing returned as an array, the desired order of the roots in the array should either :
    -be specified and enforced
    -be irrelevant.
    But since the multiplicity of roots seems to be ignored, returning a set might make sense too.