Vector operation giving complex numbers
1 view (last 30 days)
Show older comments
Prerna Mishra
on 20 Oct 2022
Edited: John D'Errico
on 20 Oct 2022
I am running the followng arithmetic.
blog_mean = 0.5000;
blog_var = 0.04;
beta = .15;
sigma = -1.14
x = blog_mean + randn(1000,1)*sqrt(blog_var);
xmod = x.^((beta*(sigma-1))/(beta*(sigma-1)-sigma));
xmod is coming out to be a complex double matrix, it really should not be. For example of the entries in x was .1078. So, xmod should have had 2.3942 correspodingly. But I get 2.3942 + 0.0000i.
How can I fix this?
0 Comments
Accepted Answer
John D'Errico
on 20 Oct 2022
Edited: John D'Errico
on 20 Oct 2022
You don't necessarily fix it, except by understanding the mathematics of what you are doing.
blog_mean = 0.5000;
blog_var = 0.04;
beta = .15;
sigma = -1.14
x = blog_mean + randn(1000,1)*sqrt(blog_var);
histogram(x)
So not all of the elements of x are greater than zero. Do you agree with that?
min(x)
Just a wee, tiny bit. But they are.
Next, you raise the elements of the vector x to a power. What power?
beta*(sigma-1)
What is a negative number, raised to a fractional power? What happens?
min(x).^(beta*(sigma-1))
The result is a complex number. Fact. It will not be a real number. It cannot be.
How can you fix it? Don't do computations that will result in complex numbers, if you don't like complex numbers as a result. Of course, we have no idea why you are doing what you are doing.
It is my conjecture that you decided to use a normal distribution because you don't know there are other distributions that would be more appropriate for this problem. As such, I would suggest you use another choice. There are other distributions that might have a sufficiently similar shape and similar properties, yet do not generate negative variates. (It might even be sfficient to use a truncated Normal.) But then, again, I have no idea WHY you are doing what you are doing.
0 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!