Square root of negative [closed] - math

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 months ago.
Improve this question
I'm a bit puzzled by these results:
result of calculating sq rt of negative number
Can someone explain what's going on?

Looks like python, in which case exponentiation is higher precedence than unary minus. So writing -5 ** .5 is treated as -(5 ** .5)

In the operator precedence table for Python, the negative operator (-x) has a lower precedence than the exponentiation operator (**).
Therefore,
-5 ** 0.5
is equivalent to
-(5 ** 0.5)

Related

Specific variables calculation [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
Hello,I have an issue.I have an excell and I want to calculate and to find Min. =0.000 etc..but I find Min. =1.700 etc. What am I doing wrong here?
I believe the problem is your inclusion of & grade as a term in your filter step.
What's going on is that R wants to interpret each of these terms (exam=="S1", year==2018, grade) as a logical value. When it converts grade to logical, 0 becomes FALSE and all other values become TRUE (try as.logical(-1:1) to see an example), so the zero values in your data get removed.
Just delete & grade from your code.

Computationally singular matrix inverse error? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
This error comes up when I am dividing by the matrix inverse.
Error in solve.default(x) :
system is computationally singular: reciprocal condition number = 6.85861e-18 ```
What are the ways to solve this? I am using the matrix.inverse function to find the inverse.
Given a matrix M, I guess it would be safe to use ginv from package MASS to compute the inverse if you want to avoid the error in your post, e.g.,
MASS::ginv(M)

The R chol2inv() method gives me strange results [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
So I'm trying to invert a big (449x449) covariance matrix, which is thus symmetric and positive definite.
(What I'm trying to do is to invert this matrix as part of a Gaussian Process fitting for the Mauna Loa CO2 dataset.)
This inversion is pretty long, so I wanted to use chol2inv instead of solve.
But the chol2inv method gives me a very strange result : a matrix very close to 0 (sum of it is equal to 10^(-13)).
Why would chol2inv give me this?
Sounds like you have wrongly used chol2inv. It takes the upper triangular Cholesky factor rather than the covariance matrix as input. So if A is your covariance matrix, you want
chol2inv(chol(A))
not
chol2inv(A)
Just found out that this issue was answered twice long long ago.
Comparing matrix inversions in R - what is wrong with the Cholesky method? (in 2014)
matrix inversion R (in 2013)

How to get the second smallest eigenvalue of the laplacian with R? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm trying to use R to capture the second smallest eigenvalue of the Laplacian of a graph, but I just know how to do it in Matlab. I have searched in the web about it, but I just always find how to use the R-function "eigen"
Does somebody can tell me how to write such a code line, please?
In Matlab, for example, the line that I use to code is:
[~, D] = eigs(lap, 2, 'sa'); %getting the first two eigenvalues of laplacian (lap). 'sa' means Smallest Algebraic
lambda2 = D(2, 2); %getting the second smallest eigenvalue
Thanks in advance for your helpful comments.
A = cbind(c(1,-1,0), c(-1,1,1), c(0.5,0.5,0.5))
ei = eigen(A)
ei$values[length(ei$value)-1]
gives second smallest eigenvalue of matrix A

How to write Prolog math functions [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
How would I write the following arithmetic expression in Prolog?
sqrt(9*log10(X)/5,9) * (1-(2X*sqrt(X)/5))^(2/7)
The square root is using the 9th root.
There is some variation between Prolog implementations, but I can promise you the following:
2X isn't going to work anywhere, except maybe a computer algebra system.
sqrt means square root. If you want to take the 9th root, you have to use a fractional exponent, such as X ** (1/9).
ISO intends ^ for integer exponentiation and ** for floating point exponentiation. Obviously, 2/7 is not an integer.
The expression you probably want is, therefore, this:
Y is (9 * log10(X) / 5) ** (1/9) * (1 - (2 * X * sqrt(X) / 5)) ** (2/7).
Notice my liberal use of whitespace. It's free, after all.
I get a lot of undefined errors for various inputs with this because you cannot take a negative number to a fractional power. I suspect this means one of us has a precedence error that can only be resolved by someone who knows what this formula is for and can compare to the original.
In the future, it would be a good idea augment your question with A) things you have tried, and B) what exactly your problem is. This question looks a lot like "do my work for me" which is probably why it's being downvoted.

Resources