MATLAB Answers

Problem while trying to solve 3 inequalities with solve function

4 views (last 30 days)
Pietro Rinaudo
Pietro Rinaudo on 14 Sep 2019
Edited: Pietro Rinaudo on 14 Sep 2019
Hi everyone, thanks in advance for any help you will provide me.
I'm struggling with a - in my opinion - basic problem involving the symbolic function solve and 3 easy inequalities: even though a solution does exist, matlab doesn't return it as output. Here is the code:
clear
clc
%s = read_txt('test.txt');
s = read_txt('test_mat.txt');
char_filler = '0';
for i = 1:size(s,1)
ss(i) = rmmissing(s(i));
end
s = ss;
for i =1:size(s,2)-11
%for i =1:size(s,2)
s(i)=strcat(s(i),char_filler);
strin = s(i);
position = regexp(strin,'[1234]');
dim = length(position);
for j = 1:dim
pos = position(j)*(j==1)+(position(j)+(j-1))*(j>1);
new_s(i)=insertAfter(s(i),pos,'*');
end
end
if exist('new_s','var')
sym_table = str2sym(new_s);
else
sym_table = str2sym(s);
end
clearvars -except sym_table new_s s
%syms a b e
soluzione = solve(sym_table,'ReturnConditions',true);
%% print
sym_table
soluzione.conditions
While the .txt files is simply (14 lines)
-e+4a>=
-e+4b<=
-e-e+3a<=
-e-e+e+2a>=
-e-e+2b+a<=
-e-e+e+b+c<=
-e+3b+a>=
-e+c+b+2a>=
-e+c+2b+a<=
-e+2c+2a>=
-e+2b+2a>=
-e+d+c+b+a<=
-e+2a+c+d>=
-c+3d+e>=
I already proved that the extraction of line is fine, and so is the final system of expressions (sym_table, 3 expressions inside as expected). The problem arises when MATLAB tries to solve it, in fact it returns the warning
Warning: Unable to find explicit solution. For options, see help.
However, with another .txt file
a+b>
a-b<
a<=
A solution if found.
I tried explicing the 3 variable (as commented) inside solve, i tried several assumptions for them, but nothing works.
Am i missing something, or simply matlab sometimes struggles with this? Because some online solvers manage to find expressions (even for bigger sets of expressions), so i'm quite in doubt.

  0 Comments

Sign in to comment.

Answers (0)


Translated by