Ask Your Question

# Problem with find_root

Hello, I'm running into a problem with "find_root." To give an example, when I use the following code, "find_root" returns a value that is not a root:

sage: var('q')

sage: h = ((q+.2(40 - q))^-0.5)/((40-q+.2(q))^-0.5) == ((q+.2(40 - q))^.5-(50)^.5+(50-8)^.5)/((40-q+.2(q))^0.5-(50)^.5+(50-32)^.5)

sage: h_a = find_root(h, 0, 40)

sage: print h_a

sage: #h_a = 11.76222222321

sage: t = ((h_a+.2(40 - h_a))^-0.5)/((40-h_a+.2(h_a))^-0.5)

sage: print t

sage: z = ((h_a+.2(40 - h_a))^.5-(50)^.5+(50-8)^.5)/((40-h_a+.2(h_a))^0.5-(50)^.5+(50-32)^.5)

sage: print z

40.0

0.447213595499989

## 3.56694309609917e13

As you can see, sage returns a root of 40, which is not a root (to check this, note that t does not equal z). My question is why find_root is doing this. There are several ways in which I could fix the problem "locally;" e.g. setting the bounds between 0 and 30 returns the correct root of 11.76, but I need to eliminate the error to apply my code to a more general problem. Please let me know if I am doing something wrong here!

Thanks!

edit retag close merge delete

## 2 Answers

Sort by » oldest newest most voted

Mpmath can give you the error message

f=lambda q:((q+.2*(40. - q))^-0.5)/((40.-q+.2*(q))^-0.5) -( ((q+.2*(40. - q))^.5-(50.)^.5+(50.-8.)^.5)/((40.-q+.2*(q))^0.5-(50.)^.5+(50.-32.)^.5))

from mpmath import *
mp.dps = 15; mp.pretty = True
s1=findroot(f,11)
print s1            # no error message
s1=findroot(f,40)   # error message

more

You can't include 40 into interval in this case

plot(h,(q,0,45),ymin=-50,ymax=50)

more

## Comments

Thank you achrzesz. right, is there any way to get find_root to return the root over the interval (0,40) instead of returning the `discontinuity'? To clarify, the problem is that it does return a value, but not the correct one (or an error message).

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2012-10-08 08:28:08 +0200

Seen: 342 times

Last updated: Oct 08 '12