Speeding up calculation with power

I am having a problem with one line of code that needs to be repeated multiple times in a loop (approximately 1 million!) and is causing long computation times. It requires raising a number to the power which i think is the cause problem. Does anyone have any suggestions to increase the speed of this? Here is the problematic line
p=4:10000;
a(p)= b.^(p-3)*c;
Any help is greatly appreciated

댓글 수: 3

I wonder if in the context you are doing that calculation, it would be feasible to re-write it in terms of logarithms? Then it would be
Log_a(4:end) = log(c) + log(b) .* (p-3);
which might be faster.
dpb
dpb 2013년 10월 26일
편집: dpb 2013년 10월 26일
Well, it's not associated with the power computation itself, but you have preallocated the result array a, haven't you?
What are b and c? Can you precompute, store and use the results of subbexpression(s) instead of recalculating every time?
And, in the end, if it's still a bottlneck there's always converting some portion to mex...
Cedric
Cedric 2013년 10월 26일
We need to see the code with what you are doing before the loop for defining and/or preallocating a,b,p,c, and the loop itself.

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

2013년 10월 26일

댓글:

2013년 10월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by