Vector operation giving complex numbers

조회 수: 1(최근 30일)
Prerna Mishra
Prerna Mishra 2022년 10월 20일
편집: John D'Errico 2022년 10월 20일
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?

채택된 답변

John D'Errico
John D'Errico 2022년 10월 20일
편집: John D'Errico 2022년 10월 20일
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);
So not all of the elements of x are greater than zero. Do you agree with that?
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?
ans = -0.3210
What is a negative number, raised to a fractional power? What happens?
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.

추가 답변(0개)


Find more on Creating and Concatenating Matrices 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!

Translated by