How to solve symbolic nonlinear equations with constrains
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponses (1)
Star Strider
le 8 Mar 2014
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 commentaires
Star Strider
le 8 Mar 2014
Modifié(e) : Star Strider
le 9 Mar 2014
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
le 9 Mar 2014
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)
Voir également
Catégories
En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!