simplify common parsing
parent
b62ec7dc55
commit
cfd9eff6fb
|
@ -124,39 +124,31 @@ while ~isempty(plus_node) || ~isempty(last_node_to_parse)
|
||||||
% Handle constraits
|
% Handle constraits
|
||||||
% Look through Xtmp names for constant
|
% Look through Xtmp names for constant
|
||||||
% if found, subtract from LHS
|
% if found, subtract from LHS
|
||||||
to_remove = [];
|
for j = length(Xtmp.name):-1:1
|
||||||
for j = 1:length(Xtmp.name)
|
|
||||||
if ~isnan(str2double(Xtmp.name{j}))
|
if ~isnan(str2double(Xtmp.name{j}))
|
||||||
lhssub = lhssub + str2double(Xtmp.name{j}) * Xtmp{j};
|
lhssub = lhssub + str2double(Xtmp.name{j}) * Xtmp{j};
|
||||||
to_remove = [to_remove j];
|
Xtmp = Xtmp.remove(Xtmp.name{j});
|
||||||
end
|
else
|
||||||
% Multiply by -1 now so that it can be added together below
|
% Multiply by -1 now so that it can be added together below
|
||||||
% Otherwise, it would matter which was encountered first,
|
% Otherwise, it would matter which was encountered first,
|
||||||
% a parameter on its own or a linear constraint
|
% a parameter on its own or a linear constraint
|
||||||
Xtmp.(Xtmp.name{j}) = -1 * Xtmp{j};
|
Xtmp.(Xtmp.name{j}) = -1 * Xtmp{j};
|
||||||
end
|
end
|
||||||
for j = length(to_remove):-1:1
|
|
||||||
Xtmp = Xtmp.remove(Xtmp.name{j});
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
parsing_error('didn''t expect to arrive here', line);
|
parsing_error('didn''t expect to arrive here', line);
|
||||||
end
|
end
|
||||||
if ~isempty(Xtmp)
|
|
||||||
to_remove = [];
|
for j = length(Xtmp.name):-1:1
|
||||||
for j = 1:length(Xtmp.name)
|
|
||||||
% Handle constraits
|
% Handle constraits
|
||||||
idx = find(strcmp(X.name, Xtmp.name{j}));
|
idx = find(strcmp(X.name, Xtmp.name{j}));
|
||||||
if ~isempty(idx)
|
if ~isempty(idx)
|
||||||
X.(X.name{idx}) = X{idx} + Xtmp{j};
|
X.(X.name{idx}) = X{idx} + Xtmp{j};
|
||||||
to_remove = [to_remove j];
|
|
||||||
end
|
|
||||||
end
|
|
||||||
for j = length(to_remove):-1:1
|
|
||||||
Xtmp = Xtmp.remove(Xtmp.name{j});
|
Xtmp = Xtmp.remove(Xtmp.name{j});
|
||||||
end
|
end
|
||||||
X = [X Xtmp];
|
|
||||||
end
|
end
|
||||||
|
X = [X Xtmp];
|
||||||
end
|
end
|
||||||
Y = Y - lhssub;
|
Y = Y - lhssub;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue