필터 지우기
필터 지우기

How to solve symbolic nonlinear equations with constrains

조회 수: 6 (최근 30일)
Dina Irofti
Dina Irofti 2014년 3월 8일
댓글: Star Strider 2014년 3월 9일
Hello!
I'd like to solve this system of equations:
function F = equationsSystem(sol)
F = [ (16*sol(1))/7 + (16*sol(2))/7 - 16/7;
- (16*sol(1)*sol(3))/7 - (16*sol(2)*sol(4))/7;
(16*sol(1)*sol(3)^2)/7 + (16*sol(2)*sol(4)^2)/7 + 2 ];
end
My constrains are:
sol(3) > 0
sol(4) > sol(3)
I'd like to have an answer like: sol(1), sol(2), sol(4) function of sol(3). How can I do this in Matlab?

답변 (1개)

Star Strider
Star Strider 2014년 3월 8일
I suggest:
syms x y z t
sys = [2.286*x+2.286*y-2.286, -2.286*x*z-2.286*y*t];
Sol = solve(sys)
Sol_x = Sol.x
Sol_y = Sol.y
to produce this:
Sol_x =
t/(t - z)
Sol_y =
-z/(t - z)
Only x and y are common to both equations, so MATLAB solves for them in terms of the other variables, z and t.
Since z and t only appear in the second equation, use it to solve for them:
Sol_z = solve(sys(2), z)
produces:
Sol_z =
-(t*y)/x
similarly:
Sol_t = solve(sys(2), t)
produces:
Sol_t =
-(x*z)/y
  댓글 수: 3
Star Strider
Star Strider 2014년 3월 8일
편집: Star Strider 2014년 3월 9일
The numerical result is highly dependent on your starting points. There appear to be a number of solutions:
% Original eqn: f = [2.286*x+2.286*y-2.286, -2.286*x*z-2.286*y*t]
% p(1) = x, p(2) = y, p(3) = z, p(4) = t
f = @(p) [2.286*p(1)+2.286*p(2)-2.286, -2.286*p(1)*p(3)-2.286*p(2)*p(4)]
opts = optimoptions('fsolve', 'MaxFunEvals',10000, 'MaxIter',10000);
s = fsolve(f, 100*ones(4,1), opts)
Your system has an infinity of solutions in {z,t}. I apologise for not guessing the ones you were thinking of.
Star Strider
Star Strider 2014년 3월 9일
So, you want sol1, sol2, and sol4 to be functions of sol3?
Let X = sol3, and solve for sol1, sol2, and sol4.
syms X
sol = sym('sol', [1 4])
assume(sol(4) > X)
assumeAlso(sol(4) > sol(3))
assumeAlso(sol(3) > 0)
assumeAlso(X > 0)
F = [ (16*sol(1))/7 + (16*sol(2))/7 - 16/7;
- (16*sol(1)*sol(3))/7 - (16*sol(2)*sol(4))/7;
(16*sol(1)*sol(3)^2)/7 + (16*sol(2)*sol(4)^2)/7 + 2 ];
F = subs(F, sol(3), X)
Sol = solve(F)
Sol_1 = simplify(Sol.sol1)
Sol_2 = simplify(Sol.sol2)
Sol_4 = simplify(Sol.sol4)
This produces:
Sol_1 =
-7/(8*X^2 - 7)
Sol_2 =
(8*X^2)/(8*X^2 - 7)
Sol_4 =
7/(8*X)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by