Prev: Can i close matlabv and continue later with the calculations?
Next: two dimensional eigenvectors
From: Marios Karaoulis on 20 May 2010 19:24 Hi, I want to find the inverse solution of this. a=rand(5,5); b=rand(5,1); a=rand(5,5); b=rand(5,1); for i=1:3 if i==1 b(1)=0; end; if i==2 b(3)=0; end if i==3 b(4)=2; end; c(:,1)=a\b; end It is obvious that I could use the parfor command. parfor i=1:3 if i==1 b(1)=0; end; if i==2 b(3)=0; end if i==3 b(4)=2; end; d=a\b; end but this error appears Error: The variable b in a parfor cannot be classified. How can i overcome it?
From: Marios Karaoulis on 20 May 2010 19:48 On May 20, 5:24 pm, Marios Karaoulis <marios.karaou...(a)gmail.com> wrote: > Hi, > I want to find the inverse solution of this. > > a=rand(5,5); > b=rand(5,1); > > a=rand(5,5); > b=rand(5,1); > > for i=1:3 > > if i==1 b(1)=0; end; > if i==2 b(3)=0; end > if i==3 b(4)=2; end; > > c(:,1)=a\b; > end > > It is obvious that I could use the parfor command. > > parfor i=1:3 > > if i==1 b(1)=0; end; > if i==2 b(3)=0; end > if i==3 b(4)=2; end; > > d=a\b; > end > > but this error appears > Error: The variable b in a parfor cannot be classified. > > How can i overcome it? correcting d d(:,i)=a\b(:,i);
From: Edric M Ellis on 21 May 2010 06:21 Marios Karaoulis <marios.karaoulis(a)gmail.com> writes: >> a=rand(5,5); >> b=rand(5,1); >> [...] >> >> parfor i=1:3 >> >> � � �if i==1 b(1)=0; end; >> � � �if i==2 b(3)=0; end >> � � �if i==3 b(4)=2; end; >> >> � � d(:,i)=a\b(:,i); % corrected >> end >> >> but this error appears >> Error: The variable b in a parfor cannot be classified. >> >> How can i overcome it? Is this code really correct? Your modifications to "b" are what's preventing this PARFOR loop from running. But each modification you're making only applies to the first column (since you're using linear indexing), and so only affects the iteration i==1. Perhaps you meant something more like this: parfor i=1:3 if i==1, b(1,i) = 0; end ... d(:,i) = a\b(:,i); end If so, that still can't run because you're modifying "b" - but since this is now order independent because you're explicitly only using the "i"th column of "b", you can re-arrange things like this: parfor i=1:3 tmp = b(:,i); % sliced read of "b" into a temporary variable if i==1, tmp(1) = 0; end % modify the temporary variable ... d(:,i) = a\tmp; end Cheers, Edric.
From: Marios Karaoulis on 21 May 2010 10:43 b is a vector. I want to sole the equation system using the same a matrix in each step but different b vector.
From: Edric M Ellis on 21 May 2010 10:52 Marios Karaoulis <marios.karaoulis(a)gmail.com> writes: > b is a vector. > I want to sole the equation system using the same a matrix in each > step but different b vector. Ah, sorry, I failed to read that part correctly. A fundamental constraint of PARFOR is that the loop iterations must be independent. By accumulating changes to "b" in this way, your iterations are not independent. You could try something like this: b = rand(5,1); .... parfor ii=1:3 tmp = b; if ii >= 1, tmp(1) = 0; end if ii >= 2, tmp(3) = 0; end if ii >= 3, tmp(4) = 2; end ... end Cheers, Edric.
|
Next
|
Last
Pages: 1 2 Prev: Can i close matlabv and continue later with the calculations? Next: two dimensional eigenvectors |