Change in subs() functionality from 2010b to 2011 a and b?
1 view (last 30 days)
Show older comments
Hi all,
I have code that has worked fine in matlab 2010b using the subs() function for symbolic substitution, however the same code give me an error when running in either the 2011a and b versions. It gives an error indicating mismatching dimension when concatenating somewhere deeper within the subs() function call. The problem arises when the original symbolic expression is a vector or matrix (scalars are fine) and the 'new' and 'old' values are cell arrays (not scalar arguments) of symbolic variables and/or expressions indicating the substitutions needed. I have tested trying to subs into each element of the original vector or matrix expression and that also works, but again can't take in the whole
Doesn't work subs(vector,{old cell}, {new cell})
Does work subs(vector(1), {old cell},{new cell})
Therefore, it seems to be an error in the new edition, although some clarification would be great and an indication if it will be fixed through a patch or something. Otherwise, I would be better of using the old version (though my license expires in 11 days) or write a function to call subs and cycle through each element of the vector or matrix expressions.
The variables in the subs() function call are:
Keq{j}
ans =
[ Keq1 - pSiOg, Keq2 - pCOg, Keq3 - pCO2g]
K>> P(1:sum(glogic))
ans =
[ pSiOg, pCOg, pCO2g]
K>> Pchgvarexp
Pchgvarexp =
[ (R*SiOg*T)/Vpore, (COg*R*T)/Vpore, (CO2g*R*T)/Vpore]
My error messages are: ??? Error using ==> sym.cat>checkDimensions at 76 CAT arguments dimensions are not consistent.
Error in ==> sym.cat>catMany at 39 [resz, ranges] = checkDimensions(sz,dim);
Error in ==> sym.cat at 29 y = catMany(dim, strs);
Error in ==> sym.horzcat at 25 y = cat(2,args{:});
Error in ==> sym.subs>tryFunctionHandle at 213 Y = [Y(:).' usym(:).'];
Error in ==> sym.subs>mupadsubs at 140 [G,worked] = tryFunctionHandle(F,X,Y);
Error in ==> sym.subs at 127 G = mupadsubs(F,X,Y);
Error in ==> ObjectiveFunBuilder_v01 at 91 Keq{j}=subs(Keq{j},P(1:sum(glogic)),Pchgvarexp);
Error in ==> GF_DataB_Cm_v01 at 39 fh = ObjectiveFunBuilder_v01(species,rxinfo,glogic);
1 Comment
Accepted Answer
Craig
on 5 Sep 2011
HI all,
I wrote a function to get around it, it works for me.
function newfn = subsVECTOR(f,old,new)
% Simple program to get around subs in MATLAB 2011 which for some reason
% they have changed.
nf = size(f,1)
for counter = 1:nf;
newfn(counter,1) = subs(f(counter,1), old, new)
end
best,
craig
0 Comments
More Answers (4)
Kai Gehrs
on 24 Aug 2011
Hi Joseph,
I have tried to run a simplified example in 10b and 11a und it does not show any errors. Here is what I have tried (hopefully the right thing if I have understood your comments correctly):
>> syms x y z
>> vector = [x y z]
vector =
[ x, y, z]
>> old_cell = {x y z}
old_cell =
[1x1 sym] [1x1 sym] [1x1 sym]
>> new_cell = {1 2 3}
new_cell =
[1] [2] [3]
>> subs(vector,new_cell,old_cell)
ans =
1 2 3
>> new_cell = {y x z}
new_cell =
[1x1 sym] [1x1 sym] [1x1 sym]
>> subs(vector,new_cell,old_cell)
ans =
[ y, x, z]
This all works fine in 10b and 11a. Maybe you have other commands involved which lead to the fact that some of your vectors/cell arrays do no longer have the expected dimensions. E.g. it may happen that results returned by 'simplify' or 'solve' have changed. But of course that's somehow speculation.
Best regards,
-- Kai
Daniel Shub
on 24 Aug 2011
While it avoids the hard part of the question: "Otherwise, I would be better of using the old version (though my license expires in 11 days) or write a function to call subs and cycle through each element of the vector or matrix expressions.
Assuming you have a license for r2011a that continues for longer than 11 days, I would contact TMW and try and arrange for an extension to r2010b.
0 Comments
Craig
on 5 Sep 2011
Hi, Any luck with this? I have pretty much the exact same problem moving from 2010a to 2011a. Best, Craig
0 Comments
Daniel Shub
on 5 Sep 2011
You should really contact customer support on this one. I did not see anything about subs in my quick look at the release notes for the symbolic toolbox in r2011a.
0 Comments
See Also
Categories
Find more on Assumptions 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!