Solve function with equations and inequations
4 次查看(过去 30 天)
显示 更早的评论
Dear all, I'm using the solve function to determine a function out of several conditions (location of maxima,fixed points, etc.). I thought about using the solve function but struggle with using equations and inequations simultaneously.
syms x_1 x_2 x_3 x_4 x_max
eqns= [3* x_1 * (x_max)^2 + 2 * x_2 * x_max + x_3 ==0 , ...
1/4 * 100^4 * x_1 + 1/3 * 100^3 * x_2 + 1/2 * 100^2 * x_3 + 100 * x_4 == 1, ...
5^3 * x_1 + 5^2 * x_2 + 5 *x_3 + x_4 ==0 , ...
100^3 * x_1 + 100^2 * x_2 + 100 * x_3 + x_4 > 2.3 ];
S =solve(eqns, [x_1 x_2 x_3 x_4 x_max]);
I now would like to insert any x_max value to receive specific values for every parameter. How can I implement this, or first: How can I solve these functions? Does anyone has an idea?
Best, Jan
0 个评论
采纳的回答
Jan GimpelHenning
2018-9-21
1 个评论
Walter Roberson
2018-9-21
MATLAB is able to handle inequalities sometimes, but it tends to return specific representative solutions instead of ranges. When it is able to handle the inequalities, then using ReturnConditions can help.
更多回答(4 个)
KSSV
2018-9-19
How about this approach?
A = rand(10,1) ; % your x_max values
x = zeros(4,length(A)) ;
for i = 1:length(A)
x_max = A(i) ;
A = [3*(x_max)^2 2*x_max 1 0 ;
1/4*100^4 1/3*100^3 1/2 * 100^2 100 ;
5^3 5^2 5 1 ;
100^3 100^2 100 1 ] ;
b = [0 ; 1 ; 0 ; 2.3 ];
x(:,i) = A\b ;
end
3 个评论
Bruno Luong
2018-9-19
编辑:Bruno Luong
2018-9-19
No, just choose b(4) anything greater than 2.3 as I and Walter told you in our respective answers.
Bruno Luong
2018-9-19
If you fix x_max and replace the last inequality by the equation
100^3 * x_1 + 100^2 * x_2 + 100 * x_3 + x_4 = 3 % (or any rhs > 2.3) (eqt4bis)
you'll get linear system of 4 unknown and 4 equations. Generally it gives a unique solution (using "\" operator).
So for each x_max, you'll get infinity solutions (x_1, ...x_4) by changing RHS of (eqt4bis) continuously from 2.3 to infinity.
0 个评论
Walter Roberson
2018-9-19
Convert to an equality.
syms x_1 x_2 x_3 x_4 x_max real
syms delta
assume(delta>0);
eqns= [3* x_1 * (x_max)^2 + 2 * x_2 * x_max + x_3 == 0, ...
1/4 * 100^4 * x_1 + 1/3 * 100^3 * x_2 + 1/2 * 100^2 * x_3 + 100 * x_4 == 1, ...
5^3 * x_1 + 5^2 * x_2 + 5 *x_3 + x_4 == 0, ...
100^3 * x_1 + 100^2 * x_2 + 100 * x_3 + x_4 == 2.3 + delta ];
S = solve(eqns, [x_1 x_2 x_3 x_4 x_max]);
x_1, x_2, and x_4 will come out in terms of delta, with x_3 and x_max coming out 0.
You can then make delta positive and arbitrarily close to 0 or as large and positive as you want
>> subs([S.x_1 S.x_2 S.x_3 S.x_4 S.x_max], delta, 10)
ans =
[ 697378134818815959/14008751663786663333750, -42103925179940864/11207001331029330667, 0, 9828603160166400041/112070013310293306670, 0]
>> subs(eqns, [x_1 x_2 x_3 x_4 x_max], ans)
ans =
[ 0 == 0, 1 == 1, 0 == 0, 123/10 == delta + 23/10]
The last of those expressions shows you that the value that would be calculated by the left side of the inequality would be 123/10, which is greater than 23/10 on the right hand side of the inequality, with the difference being the 10 that was substituted for delta
0 个评论
Alex Sha
2019-10-11
There are too many numerical solutions:
1:
x_1: 0.0219289963140093
x_2: -1.20176285580936
x_3: -33.4147964294915
x_4: 194.37692900344
x_max: -10.7432904127419
2:
x_1: 0.0314801209421686
x_2: -4.09612586532522
x_3: 126.339211496887
x_4: -533.227925969075
x_max: 20.0613135430092
3:
x_1: 0.101969454491413
x_2: -11.5043706885438
x_3: 279.570790819788
x_4: -1122.99086869677
x_max: 59.9768924098454
....
0 个评论
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!