Solving 3-variable implicit equations
9 次查看(过去 30 天)
显示 更早的评论
Hi all,
I have a system of 3 equations, with respect to 3 variables x, y and z. They are all three implicit equations, with maximum powers of 2.
How can I use MatLab to solve it?
0 个评论
回答(2 个)
Walter Roberson
2017-9-17
"maximum power 2" leaves open the possibility of cross-terms, so we need to assume the full form
syms x y z
c = sym('c',[3,10])
eqns = [c(1,1)*x^2+c(1,2)*x*y+c(1,3)*x*z+c(1,4)*y^2+c(1,5)*y*z+c(1,6)*z^2+c(1,7)*x+c(1,8)*y+c(1,9)*z+c(1,10),
c(2,1)*x^2+c(2,2)*x*y+c(2,3)*x*z+c(2,4)*y^2+c(2,5)*y*z+c(2,6)*z^2+c(2,7)*x+c(2,8)*y+c(2,9)*z+c(2,10),
c(3,1)*x^2+c(3,2)*x*y+c(3,3)*x*z+c(3,4)*y^2+c(3,5)*y*z+c(3,6)*z^2+c(3,7)*x+c(3,8)*y+c(3,9)*z+c(3,10)]
sol = solve(eqns,[x y z],'returnconditions',true)
X = solve(eqns(1),x)
eqns2 = subs(eqns(2:3),x,X(1))
Y = solve(eqns2(1),y);
eqns3 = subs(eqns2(2),y,Y(1))
Z = solve(eqns3, z)
X has two solutions; we pick one of the branches for further exploration.
Y has four solutions. Each expression for Y is too long to fit on the screen. We pick one of the branches for further exploration.
The symbolic engine cannot find z in this general coefficient case. It might be able to find z for particular numeric coefficients, but I would not count on it unless there are no cross terms.
0 个评论
John D'Errico
2017-9-16
If the equations have symbolic coefficients, then you have no choice but to use solve.
If all of the coefficients are known numeric values, then you can try to use solve. There is a good chance that no analytical solution exists however. Think of it like this. The basic idea is you take one equation, and solve it for say variable 1, then substitute that variable into the others to eliminate variable 1. This is essentially the idea of Gaussian elimination. It works nicely, and if your equations are all low order polynomial, it is possible to do, to some extent.
The problem arises when you start with second order equations, they effectively grow in order. So three second order equations probably turn into two fourth order equations. You can still solve a 4th order equation though, for one of the variables. But now you may end up with one 8th order equation, with only one variable remaining. Just solve that equation. Except, you can't solve an equation of higher than order 4, if your goal is a solution expressible exactly. At best, all you can do in that case is to find a numerical solution, such as that which roots provides.
So solve will probably have a minor hiccup, and be then reduced to finding numerical approximations to the roots. Solve may throw a warning message to that effect. Still ok, as long as you understand what happened.
If you don't have the symbolic toolbox, then you won't be able to use solve anyway. So then you need to use a numerical tool, such as fsolve, from the optimization toolbox. Note that fsolve will find only ONE solution, depending on your starting values for the search.
Finally, you could also formulate the problem for a tool from the global optimization toolbox. Since it deals with optimization instead of rootfinding though, you will need to minimize the sum of squares of the deviations from zero for all the three equations. You could even do that with fminsearch of course.
If you don't have one of those toolboxes, then rather than writing code, buy the symbolic or optimization toolbox (whichever would then apply).
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!