0

I would like find the roots of equation x2-x-6 using Newton Raphson method.

how to take initial value x0 by coding.

tried with for loop
for k in list(range(i-1, i)):
    print("x0", k)
    new_fun(x0)
    x0 = k + 0.5
    print(x0)

Where i and i-1 are boundaries

  • How exactly do you want to set this value? You could just replace the input line with `x0 = 0`, for instance. Did you instead want a randomly selected initial value? – Ben Grossmann Feb 01 '22 at 21:14
  • Yes, but i want to loop through i-1, i with increasing numbers 0.5 or 1. I tried for loop but it is giving for first value then it is not looping through next values – crazycoders Feb 02 '22 at 01:22
  • What exactly is `i` in this context? Note that `list(range(i-1,i))` is a list that contains only the value `i-1`, but I suspect that this is not what you are looking for – Ben Grossmann Feb 02 '22 at 02:04

1 Answers1

0

A for loop that seems much more reasonable to me is the following.

m_min = 0  # min value
x_max = 10 # max value
dx = 0.5  # increment

for x0 in range(x_min,x_max+dx,dx):
    print("x0:",x0)
    newton(x0)
Ben Grossmann
  • 4,387
  • 1
  • 12
  • 16