이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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);
%puts output together
f = M2(:,Integer)-TheSum;
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.


Walter Roberson
Walter Roberson 2016년 12월 3일
Your lines
for n=1:(Integer-1)
TheSum = M1(Integer,n)*fF(M1,M2,n);
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