Order of variables in SOLVE
조회 수: 4 (최근 30일)
이전 댓글 표시
clear all
syms x y l1 l2 l3 %%Generate symb var for multipliers
v=[x y l1 l2 l3];
g1=(y-3)/sqrt((x-2)^2+(y-3)^2)+l1+l2-l3; %%Gradient condition
g2=(x-2)/sqrt((x-2)^2+(y-3)^2)+l1;
cs1=l1(x+y); %%Complementary slackness conditions
cs2=l2*(x-2);
cs3=l3*(x+2);
[x, y, l1, l2, l3] = solve(g1==0,g2==0,cs1==0,cs2==0,cs3==0, x, y, l1,...
l2, l3);
sol=[x, y, l1, l2, l3];
I have this KKT system. Other times when I used the solve command I noticed that in the solution matrix the variables are not reported in the specified order.
How do I make sure that in the sol matrix the variable are the right one (without checking manually, that is).
In the example above, having the solutions, I can see that into sol x,y are the two rightmost columns. If I switch like this
[ l1, l2, l3, *x, y,*] = solve(g1==0,g2==0,cs1==0,cs2==0,cs3==0, x, y, l1,...
l2, l3);
then everything goes ok. I need to now why this happens in order not to make this mistake again when I don't have solutions. Thanks
댓글 수: 0
채택된 답변
Walter Roberson
2013년 5월 14일
Use the structure return form of solve and then extract by structure field name into the variables you want.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!