Can you tell us a little of the context ... what sort of problem are you trying to solve, and why do you think the square root of this value leads towards the solution.
The problem here is not in your program -- it has given you the correct answer as far as it is able.
Are you familiar with any of the following mathematical terms:
... Integer
... Rational Number
... Irrational Number
... Real Number
... Imaginary Number
... Complex Number
These are the names for various sets of numbers. When solving numerical problems it can sometimes help to think through which set(s) your inputs and output(s) belong to. It is easy to fall into the trap of assuming that floating-point variables lead to the most accurate results, but that isn't always true.
C/C++ use the floating-point types (float, double) to represent a subset of the Real Numbers. The inputs to and output from pow() are all floating-point (Real) numbers. The term "NaN" is an acronym for "not a number".
There are no Real Numbers that when squared yield a negative number. That is, the square root of a negative number is not a Real Number. There is an answer, but it isn't a Real Number. Try to solve your problem with a calculator.
For C89 and C++ (or a calculator) you need to understand the mathematics well enough to express the problem differently (into a form that can be solved with real numbers) and then reinterpret the real number result to get the final answer.
C99 has an extended math library that can actually solve this problem directly; but you won't be able to use it if you don't understand the underlying mathematics well enough to set up the problem properly.
Can you tell us a little of the context ... what sort of problem are you trying to solve, and why do you think the square root of this value leads towards the solution.
I am calculating the covarience for some problem , from that result finding cross covarience. The covarience is giving -ve number which i want it raise to the power of 0.5. If i use pow(-0.6585,0.5) it gives nan . how do i need to calculate. how do i calculate this problem.
Why do you want to take the square root of that covariance? If it is negative then
you know that a series X decreases while a series Y increases and vice versa.
Why do you want to take the square root of that covariance? If it is negative then
you know that a series X decreases while a series Y increases and vice versa.
When I say SquareRoot below I'm referring to the mathematical square root operation, not a C/C++ function.
One well-known property of SquareRoot is the following ...
SquareRoot(a*b) = SquareRoot(a) * SquareRoot(b)
It therefore follows that
SquareRoot(-0.7658) = SquareRoot(0.76 58) * SquareRoot(-1)
The first term can be readily computed on a calculator or via the C/C++ pow function. The second term is, by definition, the value i (the imaginary unit).
That is, SquareRoot(-0.7658) = 0.8751i (an Imaginary Number).
I don't see how that helps you draw a graph.
When I say SquareRoot below I'm referring to the mathematical square root operation, not a C/C++ function.
One well-known property of SquareRoot is the following ...
SquareRoot(a*b) = SquareRoot(a) * SquareRoot(b)
It therefore follows that
SquareRoot(-0.7658) = SquareRoot(0.76 58) * SquareRoot(-1)
The first term can be readily computed on a calculator or via the C/C++ pow function. The second term is, by definition, the value i (the imaginary unit).
That is, SquareRoot(-0.7658) = 0.8751i (an Imaginary Number).
I don't see how that helps you draw a graph.
Thanks a lot for u r solution.
Is there anny way to convert from a+bi to real number
Thanks a lot for u r solution.
Is there anny way to convert from a+bi to real number
No there isn't. The set of real numbers is a real subset of the set of complex numbers.
iow there exist numbers in the complex set that are not in the real set. Any number
a+bi for b != 0 is such a number.
Comment