Solving nonlinear minimization equations symbolically in matlab

£可爱£侵袭症+ 提交于 2019-12-12 02:39:47

问题


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);

回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/18532932/solving-nonlinear-minimization-equations-symbolically-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!