Clear Filters
Clear Filters

Syms variable cannot be classified?

1 view (last 30 days)
In the code below, the variable Qv cannot be classified, and I have no idea why. From the documentation at 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,:));
Qj(j,:) = Qv;
Qj(j,:) = 0;
QQ(i,:) = num2cell(Qj);

Accepted Answer

Walter Roberson
Walter Roberson on 11 Aug 2018
(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:
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;
variable = sym(zeros(Size))
such as
qv = sym( zeros(1, size(CC{i,j},2)) );
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 Comment
Eric Chadwick
Eric Chadwick on 13 Aug 2018
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!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!