0

I have a large underdetermined equation system for which I search an unique solution in respect of any given constraints. I simplified my problem into the following one:

x²-4=0,
y²-9=0,
x*y=myMin,
x+y=myMin.

What is the best way to implement this in Matlab symbolically, so that it returns

x=2
y=-3

I'm searching something like

syms x y
S=solve(...
x²-4==0,...
y²-9==0,...
x*y==myMin,...
x+y==myMin);
Dennis Jaheruddin
  • 21,208
  • 8
  • 66
  • 122
Caniko
  • 867
  • 2
  • 11
  • 28
  • Have you tried `help solve`? What happens when you try to use the solver? Don't have the symbolic toolbox available but it should work for symbolic equations. – Dennis Jaheruddin Aug 30 '13 at 14:18
  • It says it's not possible to solve something like this symbolically with matlab... – Caniko Aug 30 '13 at 14:21

2 Answers2

1

I do not know how specify the min as a function command to solve. But here's an approach that solves the equations and then post-processes the result according to your constraints:

syms x y
S=solve(x^2-4==0,y^2-9==0);

[~,idx] = min(double(S.x .* S.y)+double(S.x + S.y));

X = double(S.x(idx))
Y = double(S.y(idx))

This gives:

X =
  2

Y =
 -3 

The symbolic results have to be converted using the double command to allow processing with the min function.

Schorsch
  • 7,761
  • 6
  • 39
  • 65
  • Assuming you guessed correctly what the asker wanted (to use the first two equations as constraints and the sum of the other two as objective function) this solution is very nice! – Dennis Jaheruddin Aug 30 '13 at 14:33
  • @DennisJaheruddin It's more a gut-feeling that the two constraints can be expressed like that. – Schorsch Aug 30 '13 at 14:35
  • The struct S has 2 symbolic 2x1 vectors. This is why you can multiplicate it each other and work with them as vectors. But in my case the variables would depend on each other so that you couldnt't convert it into double. Your answer does it for my example but not as an optimization problem. – Caniko Aug 30 '13 at 15:12
  • @Caniko how different is your actual problem from what you *really* want? Are your functions of different orders so that you get a different number of `x` values compared to `y` values? Because the idea of evaluating your constraints after the fact should still be applicable. – Schorsch Aug 30 '13 at 17:37
0

The problem you seem to run into is that there is no solution, not even matlab can deal with that.

Try it like this:

myMin = -6;

syms x y
S=solve(...
x²-4==0,...
y²-9==0,...
x*y==myMin,...
x+y==myMin + 5); %Note the +5 to make it feasible

Cannot try myself, but a quick calculation tells me that this one is at least solvable.

Dennis Jaheruddin
  • 21,208
  • 8
  • 66
  • 122
  • If you are not sure on how to use functions, that is usually a good starting point. However, my point was actually that your initial problem was infeasible. At least in the way you defined it, perhaps not in the way you intended it. – Dennis Jaheruddin Aug 31 '13 at 12:24