I have an array of numbers, $B$, that can be written as $B = A^2$, where $A$ is also an array of numbers consisting of positive and negative numbers.
If I take the square root of $B$ in MatLab using $C = \sqrt{B}$ I will only get the positive values of $A$. Is there a way to get the negative values of $A$?
Thinking about it, it is probably impossible to do this since Matlab would have to guess which values are negative. Am I right?
I am not sure if I know what you are asking, but if $B$ is some matrix,
sqrt(B)will do the trick;sqrt(B)will accept negative values and give you a complex number back. If you are looking to do square roots of complex numbers, then you will need to use polar coordinates.EDIT After your edit, what you are looking for is both the negative and positive solutions to $y = x^2$, i.e. $y = \pm \sqrt{x}$. There is not an immediate way to do so in matlab, that I know of. What you could do is just declare a new matrix
D = -sqrt(B). You could use conditional loops, but that is probably more pain than it is worth. After declaring matrixD, the $(i,j)$-entry would be the opposite sign of the $(i,j)$-entry insqrt(B). From there, if you really wanted both answers in one matrix, you could define a new $n \times n \times 2$ array. Of which the $n \times n \times 1$ entry issqrt(B)and the $n \times n \times 2$ entry is-sqrt(B).Also, as the comment points out, there is no way to know for certain that if $y = x^2$, then $x$ was the negative/positive solution (I guess if someone trivially told you). Otherwise, we just say it is either $-\sqrt{y}$ or $\sqrt{y}$