Vector operation giving complex numbers

1 visualización (últimos 30 días)
Prerna Mishra
Prerna Mishra el 20 de Oct. de 2022
Editada: John D'Errico el 20 de Oct. de 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?

Respuesta aceptada

John D'Errico
John D'Errico el 20 de Oct. de 2022
Editada: John D'Errico el 20 de Oct. de 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
sigma = -1.1400
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)
ans = -0.1215
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)
ans = -0.3210
What is a negative number, raised to a fractional power? What happens?
min(x).^(beta*(sigma-1))
ans = 1.0488 - 1.6641i
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.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by