1

I am using Matlab R2014a.

I need to find the answer to a set of inequalities and then use it in a script. I used solve([eq1,eq2],x) but the answer is a MuPad syntax so I can't change it to a double or float to use in other calculations. Is there an alternative way to solve system of inequalities, or a way to extract information from Dom::Interval(x1,x2)?

syms x
eq1= x>0 ;
eq2= x<3 ;
solve([eq1,eq2],x)

Output is:

"Dom::Interval(0, 3)"

and unusable for scripts.

How do I solve the problem?

Emma
  • 27,428
  • 11
  • 44
  • 69

1 Answers1

0

If your goal is to solve a system of equations while constraining the variables to a given set of ranges, you're better off using assume to set assumptions for each variable. For example:

>> syms x;
>> eq1 = x>0;  % Lower constraint
>> eq2 = x<3;  % Upper constraint
>> solve(sqrt(x^2-4)==0, x)  % An equation with 2 solutions

ans =

  2
 -2

>> assume(eq1 & eq2)  % Constrain x
>> solve(sqrt(x^2-4)==0, x)

ans =

2  % Only the solution that satisfies the constraints is returned
gnovice
  • 125,304
  • 15
  • 256
  • 359