hi, i got the following code. Is there a way to completly vectorize it ? or rather a better way of programming this for faster execution in e.g fmincon.
c=positive_int;
j=0:50;
alpha(0+1,j+1)= gamma((c.*j)+1)./gamma(j+1);
cache=zeros(51,1);
for n=1:1:10
for j=n:1:50
for m=n-1:1:j-1
cache(m+1)= alpha(n-1+1,m+1)*gamma((c*j)-(c*m)+1)/gamma(j-m+1);
end
alpha(n+1,j+1)=sum(cache);
cache(:)=0;
end
end
So far it got this.
c=positive_int;
j=0:50;
alpha(j+1,0+1)= gamma((c.*j)+1)./gamma(j+1);
variable=50;
[mValues, nValues] = meshgrid(0:variable, 0:variable);
mask = nValues <= mValues;
for n=1:1:10
[j,m]=meshgrid(n:1:50 ,n-1:1:49);
cache= alpha(m(1:50-n+1)+1,n-1+1).*gamma((c.*j)-(c.*m)+1)./gamma(j-m+1);
mask(51-n,:)=[];
mask(:,51-n)=[];
cache=cache.*mask;
cache(isnan(cache))=0;
cache=sum(cache);
alpha(n+1:end,n+1)=cache;
end
But that seems a bit complex coded and is not that huge improvement.