필터 지우기
필터 지우기

Why I have wrong result in (power) function?

조회 수: 2 (최근 30일)
Abdulatif Alabdulatif
Abdulatif Alabdulatif 2014년 11월 7일
댓글: Star Strider 2014년 11월 8일
Hi all,
I have the following statement which generate wrong result:
temp1 = power(x,temp1)
The wrong result is:
temp1 =
Inf
if I change ( temp1 ) to a number it works! but f I use a variable (temp), it does not work.
Any help?
Thank you

답변 (1개)

Star Strider
Star Strider 2014년 11월 7일
The variables x and temp1 have to be numeric in core MATLAB, as it seems you are doing.
If you’re doing symbolic calculations, you need to use the Symbolic Math Toolbox.
  댓글 수: 7
Abdulatif Alabdulatif
Abdulatif Alabdulatif 2014년 11월 8일
편집: Abdulatif Alabdulatif 2014년 11월 8일
I have to perform modulus operation after find the power result.
x=3
temp1= 25111
temp1 = power(x,temp1)
result = mod(temp1,7);
Is it possible to perform (mod) operation with float-point numbers?
I already found alternative solution by perform (for loop) but it is slow in term of performance.
Star Strider
Star Strider 2014년 11월 8일
I doubt that what you want to do is possible. At least I can’t imagine how to do it, because it would involve both division and subtraction, and that would involve raising some multiple of 7 far beyond the ability of MATLAB floating-point precision in order to do the subtraction. (I doubt if it would even be possible to factor it.)
I don’t know how you could do this with a for loop, because you could not represent 3^25111 in MATLAB at all, to the best of my knowledge. I can envision doing it in assembler with serial multiplications of 3 then serial divisions by 7, but that isn’t something I’d want to do.
If you did manage to solve this with for loops, please post your code.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by