Error Messages/4294941821

Warning Message

Warning:
Square root of a negative number.

Cause

This warning is issued when the Show Result Warnings preference is on and an attempt is made to take a square root of a negative number. If the warning is ignored, the result will be NaN.

When taking the square root of an array, Sqrt(A), the warning may display if any value in the array is negative.

Remedy

There are two methods for avoiding this warning without turning Show Result Warnings globally. These are demonstrated here.

If A>=0 Then Sqrt(A) Else Null
IgnoreWarnings(Sqrt(A))

The first instance is convenient and readable when you have a particular substitution value in mind. The second method evaluates faster.

Complex Numbers

What if you really do want to take the Sqrt of a negative number, and obtain a complex number?

For that, use CSqrt in the Complex Number Library.

Comments


You are not allowed to post comments.