Syms variable cannot be classified?

조회 수: 2 (최근 30일)
Eric Chadwick
Eric Chadwick 2018년 8월 10일
댓글: Eric Chadwick 2018년 8월 13일
In the code below, the variable Qv cannot be classified, and I have no idea why. From the documentation at https://www.mathworks.com/help/distcomp/troubleshoot-variables-in-parfor-loops.html it looks like I am following all of the rules. My code looks like the one on the top right example and I reset my variable using "syms Qv". The only fix I noticed was making the variable not symbolic, but that is a requirement for the variables since I am building a matrix of linear equations that I intend to solve.
I can attach files with the variables needed to run this but basically dd is just a cell array of diameters, ll is a cell array of lengths, CC is a cell connectivity matrix, and pns is a symbolic array with some unknown values and some known values.
Anyone know what is wrong here? Thanks in advance.
parfor i=1:size(CC,1)
h = 0;
syms Qj
for j=1:size(CC)
syms Qv;
if ~isempty(CC(i,j))
k = 0;
h = h+1;
k(h) = j;
for vess = 1:size(CC{i,j})
Qv(vess,:) = -((dd{i,j}(vess,:)^3)/(12*mu))*((pns(i)-pns(j))/ll{i,j}(vess,:));
end
Qj(j,:) = Qv;
else
Qj(j,:) = 0;
end
end
QQ(i,:) = num2cell(Qj);
end

채택된 답변

Walter Roberson
Walter Roberson 2018년 8월 11일
(A) Your code has too much confusion over how you use size(). When you do not pass in a dimension number, size() returns a vector, and when you count on using a vector as one of the bounds of a "for" loop then you likely have a bug.
(B) Do not syms up a scalar variable and then index into it. Do one of the following instead:
1)
variable = sym('prefix', [Size])
such as
qv = sym('qv', size(CC{i,j}));
This initializes the output as an array of symbol names that start with the prefix and have array indices built in, such as qv3_5 . You probably do not want this in your case;
2)
variable = sym(zeros(Size))
such as
qv = sym( zeros(1, size(CC{i,j},2)) );
or
3)
variable = zeros(Size, 'sym');
such as
qv = zeros(1, size(CC{i,j},2), 'sym');
This is more efficient than (2) but requires a newer MATLAB.
  댓글 수: 1
Eric Chadwick
Eric Chadwick 2018년 8월 13일
Hi there! Thank you so much for your answer! I have made the changes you suggested and used solution (B) 3) and it works great!
Cheers,
Eric

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by