parfor with fminunc where fminunc returns a vector
Show older comments
Hi,
I am running a parfor loop inside which I use fminunc and I get the following error:
Starting matlabpool using the 'local' profile ... connected to 12 labs.
Error using parallel_function (line 589)
User supplied objective function must return a scalar
value.
Error stack:
fminunc.m at 324
Error in untitled8_noprices (line 72)
parfor j=1:J % loop for firms (column of matrices)
Is there some way to fix if I screwed something or to go around any limitations that I might be running into?
I attach my code under so that you can look at it/make suggestions
------------------------------------------------
while dif>tol && its<maxits
parfor j=1:J
for i=1:N
for ii=1:N
k0=kmat(i,j);
m0=mmat(ii,j);
km0=[kmat(i,j),mmat(ii,j)];
km1 = fminunc(@(km) firmprob_2cap_noprices(km,j,vold,k0,m0,Agrid),km0);%,options);
vnew(i,ii,j) = -firmprob_2cap_noprices(km1,j,vold,k0,m0,Agrid);
kopt(i,ii,j) = km1(1);
mopt(i,ii,j) = km1(2);
Ymat(i,ii,j)=Agrid(j)*(k0^alpha)*(m0^alpha)-km1(1)-km1(2);
end
end
end
if its>=maxits;
fprintf('Ran out of iterations \n');
end
for jj=1:J
diff(1,jj)=norm(vnew(:,:,jj)-vold(:,:,jj));
end
dif=max(diff)
vold = vnew;
its = its+1;
end
3 Comments
J
on 14 Jul 2012
Walter Roberson
on 14 Jul 2012
We will need to see firmprob_2cap_noprices
J
on 14 Jul 2012
Edited: Walter Roberson
on 14 Jul 2012
Accepted Answer
More Answers (1)
J
on 14 Jul 2012
0 votes
Categories
Find more on Performance and Memory in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!