0

Answered # What does math domain error mean

I tried to find the square root of a negative number while writing a function to solve quadratic equations but the interpreter said something , it said math domain error, what does this mean. Even though I've been able to solve the quadratic equation using complex numbers and i will be posting it very soon, i want to know when to expect such errors

Featured Reply pyTony 888 Discussion Starter e-papa 13

0

1

Maybe you understand from this interactive session by 'no comments' style:

```
>>> from math import *
>>> sqrt(-1)
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
sqrt(-1)
ValueError: math domain error
>>> sqrt(-1+0j)
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
sqrt(-1+0j)
TypeError: can't convert complex to float
>>> a = -1+0j
>>> a
(-1+0j)
>>> sqrt(a)
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
sqrt(a)
TypeError: can't convert complex to float
>>> log(-3)
Traceback (most recent call last):
File "<pyshell#7>", line 1, in <module>
log(-3)
ValueError: math domain error
>>> import cmath
>>> help(cmath)
Help on built-in module cmath:
NAME
cmath
FILE
(built-in)
DESCRIPTION
This module is always available. It provides access to mathematical
functions for complex numbers.
FUNCTIONS
acos(...)
acos(x)
Return the arc cosine of x.
acosh(...)
acosh(x)
Return the hyperbolic arccosine of x.
asin(...)
asin(x)
Return the arc sine of x.
asinh(...)
asinh(x)
Return the hyperbolic arc sine of x.
atan(...)
atan(x)
Return the arc tangent of x.
atanh(...)
atanh(x)
Return the hyperbolic arc tangent of x.
cos(...)
cos(x)
Return the cosine of x.
cosh(...)
cosh(x)
Return the hyperbolic cosine of x.
exp(...)
exp(x)
Return the exponential value e**x.
isinf(...)
isinf(z) -> bool
Checks if the real or imaginary part of z is infinite.
isnan(...)
isnan(z) -> bool
Checks if the real or imaginary part of z not a number (NaN)
log(...)
log(x[, base]) -> the logarithm of x to the given base.
If the base not specified, returns the natural logarithm (base e) of x.
log10(...)
log10(x)
Return the base-10 logarithm of x.
phase(...)
phase(z) -> float
Return argument, also known as the phase angle, of a complex.
polar(...)
polar(z) -> r: float, phi: float
Convert a complex from rectangular coordinates to polar coordinates. r is
the distance from 0 and phi the phase angle.
rect(...)
rect(r, phi) -> z: complex
Convert from polar coordinates to rectangular coordinates.
sin(...)
sin(x)
Return the sine of x.
sinh(...)
sinh(x)
Return the hyperbolic sine of x.
sqrt(...)
sqrt(x)
Return the square root of x.
tan(...)
tan(x)
Return the tangent of x.
tanh(...)
tanh(x)
Return the hyperbolic tangent of x.
DATA
e = 2.7182818284590451
pi = 3.1415926535897931
>>> cmath.sqrt(-1)
1j
>>> cmath.log(-3)
(1.0986122886681098+3.1415926535897931j)
>>>
```

0

Thanks now i understand why my quadratic function is not working, thanks a lot tonyjv for the honest criticism, will work on it and it will come back better.

This question has already been answered. Start a new discussion instead.

Recommended Articles

Help! I want to create a java program that finds the highest even integer among the values entered by the user. Stop asking values when a value less than 1 have been entered. If no even integer is entered, display "No Even Integer"

Here is the sample output that I ...

Hello All ...

Iam Getting An Error With try to excecute the stored procedure .

I have Have Sql database , the stored procedure like so :

```
USE [MPRS]
GO
/****** Object: StoredProcedure [dbo].[Search_Licenses_By_Number] Script Date: 26-Nov-16 8:06:52 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE ...
```

I don’t want at this stage work on a big separate project as I've already got plenty ...