Why power function give a complex number result?
조회 수: 16 (최근 30일)
이전 댓글 표시
Bundit Boonkhao
2019년 11월 1일
답변: Ildeberto de los Santos Ruiz
2019년 11월 1일
I have tried to create Rosin-Rammler function for own use with my code
function q = rosinrammler(x, x50, n)
q = 1 - exp((-x/x50)^n);
However, when I input the value for example x = 2e-9, x50 = 100e-9 and n = 0.1 the output show me the complex number such as
q = rosinrammler(2e-9, 100e-9, 0.1)
q =
-0.861067915307539 - 0.394670349292600i
Where I think the result shoud be real number such as 0.491476239432908. This results I mannually calculate from 1 - exp(-0.02^0.1). I have found that the complex numer is generated when I try to power (-x/x50)^n.
So if anyone can help me, please I am very appreciate
Thank you
Bundit
댓글 수: 0
채택된 답변
Walter Roberson
2019년 11월 1일
1 - exp(-0.02^0.1)
implies taking 0.02^0.1 and taking the negative of that, and taking exp() of the result; this would be the same as 1/exp(0.02^01)
However, that is not what is coded. What is coded is exp((-x/x50)^n) which is exp((-positive/positive)^n) which is exp((negative number)^n) . negative number raised to a non-integer power is going to give a complex result
Be careful with where you put the negative signs.
댓글 수: 0
추가 답변 (1개)
Ildeberto de los Santos Ruiz
2019년 11월 1일
The "problem" appears when you raise the base (-x / x50) to power n.
In IEEE floating-point computations:
a ^ n = exp(n * log(a))
In your example, the base a is negative, hence the logarithm is a complex number.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Thermal Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!