フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

how to mex this recursion

1 回表示 (過去 30 日間)
DoVile Last Name:
DoVile Last Name: 2016 年 12 月 3 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I am running a large program and a small function is taking up all the computing time, I havent been able to use the automatic c coder app because the function is recursive - what can I do ?
function f = fF(M1,M2,Integer)
%initialize to zero
TheSum = 0;
%loop with recursion
for n=1:(Integer-1)
TheSum = M1(Integer,n)*fF(M1,M2,n);
end
%puts output together
f = M2(:,Integer)-TheSum;
end
M1 and M2 are matrices, Integer is an Integer :)
  1 件のコメント
John D'Errico
John D'Errico 2016 年 12 月 3 日
編集済み: John D'Errico 2016 年 12 月 3 日
Just creating a mex from this will not magically make it more efficient.
Instead, think about WHY it is spending so much time. We cannot really know anything, since you have told us nothing of value. What are these numbers? Just telling us they are integers is silly. 1 is an integer, so is zero. But your code will likely run quickly if Integer is 0 or 1. Tell us the actual values.
The crystal ball is so foggy.

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 12 月 3 日
Your lines
for n=1:(Integer-1)
TheSum = M1(Integer,n)*fF(M1,M2,n);
end
can be written less recursively as
TheSum = M1(Integer, Integer-1) * fF(M1, M2, Integer-1) ;
with no loop. Are you sure that was your intention?
What is the purpose of your routine? It reminds me of calculating determinants.

この質問は閉じられています。

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by