Egor Kozitski

Greenhorn

Posts: 3

Egor Kozitski

Greenhorn

Posts: 3

Campbell Ritchie

Marshal

Posts: 56536

172

posted 2 years ago

Welcome to the Ranch

That looks too complicated for “Beginning” so I shall move it.

You cannot usually correct code like that. you should work out the algorithm on paper first and then convert that to code. Please start by writing down what the algorithm is.

That looks too complicated for “Beginning” so I shall move it.

You cannot usually correct code like that. you should work out the algorithm on paper first and then convert that to code. Please start by writing down what the algorithm is.

Egor Kozitski

Greenhorn

Posts: 3

posted 2 years ago

I enchanced my algorithm a bit and now I am getting a "better output" , but its not correct

Here is my algorithm

Evaluate the polynomial at root, x0 (starting with an initial guess):

result = f(x0)

2. If the maximum number of iterations was exceeded, or the

absolute value of result is less than or equal to some epsilon

of error difference, return the root, x0.

3. Otherwise, compute the new root using Newton's Method:

x1 = x0 - f(x0)/f'(x0)

4. Recurse with new root, x1.

Here is a new code

The rest of the code was not change

I am testing this input [3,-1] and my output is 3.524746445015649

But the right output is 3.0

Here is my algorithm

Evaluate the polynomial at root, x0 (starting with an initial guess):

result = f(x0)

2. If the maximum number of iterations was exceeded, or the

absolute value of result is less than or equal to some epsilon

of error difference, return the root, x0.

3. Otherwise, compute the new root using Newton's Method:

x1 = x0 - f(x0)/f'(x0)

4. Recurse with new root, x1.

Here is a new code

The rest of the code was not change

I am testing this input [3,-1] and my output is 3.524746445015649

But the right output is 3.0