Matlab matalb中幂函数的快速逼近与实现
我可以在以下问题中找到C/C++的类似答案: 根据分析器,我的代码的瓶颈类似于以下代码:Matlab matalb中幂函数的快速逼近与实现,matlab,Matlab,我可以在以下问题中找到C/C++的类似答案: 根据分析器,我的代码的瓶颈类似于以下代码: a=rand(100,1); % a is an array of doubles b=1.2; % power can be double instead of only integers. temp=power(a,b); % this line is taking maximum time 根据我的要求,只有前3-4位是有效的,所以任何快速的幂近似对我都非常有用。有什么建议可以这样做吗 更多信息:
a=rand(100,1); % a is an array of doubles
b=1.2; % power can be double instead of only integers.
temp=power(a,b); % this line is taking maximum time
根据我的要求,只有前3-4位是有效的,所以任何快速的幂近似对我都非常有用。有什么建议可以这样做吗
更多信息:
这就是我使用exp和log计算功率的方法。这大约提高了50%。现在我需要找到log和exp的近似函数,并检查这是否更快
a=rand(1000,1);
tic;
for i=1:100000
powA=power(a,1.1);
end
toc;
tic;
for i=1:100000
powB=exp(1.1*log(a));
end
toc;
Elapsed time is 4.098334 seconds.
Elapsed time is 1.994894 seconds.
从数学上讲,近似值应该知道
a
和b
的范围,否则用timeit
来计算代码的时间就太宽泛了。