Python Forum
Solving an equation by brute force within a range
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solving an equation by brute force within a range
#4
(Aug-09-2022, 09:20 AM)Estherbarnes Wrote: (x**0.5) isn't the same as square root, it gives another result, doesn't it? Huh
When x is a nonnegative float, it should give the same result, but it turns out that for negative floats, Python returns the principal complex square root for x**0.5 while sqrt(x) raises a math domain error. So these are not exactly the same functions.
>>> (-1)**0.5
(6.123233995736766e-17+1j)
>>> from math import sqrt
>>> sqrt(-1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: math domain error
For a general object, the expression x ** 0.5 returns x.__pow__(0.5), so the result depends on how the class of x defines the __pow__() method, which can be very arbitrary.
Reply


Messages In This Thread
RE: Solving an equation by brute force within a range - by Gribouillis - Aug-09-2022, 09:44 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question written RK solving same equation with different graphs acbshinn 1 419 Feb-09-2024, 12:33 PM
Last Post: Gribouillis
  Need an alternative to brute force optimization loop jmbonni 5 1,200 Dec-07-2023, 12:28 PM
Last Post: RockBlok
  force a program to exit ? Armandito 3 2,566 May-12-2022, 04:03 PM
Last Post: Gribouillis
  Solving equation equal to zero: How to resolve the syntax error? alexfrol86 3 1,995 Feb-21-2022, 08:58 AM
Last Post: deanhystad
  matplotlib x axis range goes over the set range Pedroski55 5 3,244 Nov-21-2021, 08:40 AM
Last Post: paul18fr
  Solving for zeros of an equation! fmitchell17 0 1,846 Apr-05-2021, 07:49 PM
Last Post: fmitchell17
  How to use scipy.optimization.brute for multivariable function Shiladitya 9 6,306 Oct-28-2020, 10:40 PM
Last Post: scidam
  best way to force an exception Skaperen 2 2,071 Oct-21-2020, 05:59 AM
Last Post: Gribouillis
  I need advise with developing a brute forcing script fatjuicypython 11 5,116 Aug-21-2020, 09:20 PM
Last Post: Marbelous
  How to Solving non-linear equation using scipy.optimize fsolve with variable list djhak 3 4,568 Jun-10-2020, 04:12 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020