Solving 3 equations with 3 unknowns gives Warning: Explicit solution could not be found > In solve at 179
1 次查看(过去 30 天)
显示 更早的评论
I am very new to Matlab and I wrote this code to find the solutions for x, y and l for three equations. Here is the code I used;
syms x positive
syms y positive
syms m n e f l b c d
S = solve((y/((x+y)^2))*(m+e+l*d*m-l*d*n-((2*l*d+1)*((b*x)/(x+y)))+((2*l*d*b*y)/(x+y)))-l-c == 0,
(x/((x+y)^2))*(n+f+l*d*n-l*d*m-((2*l*d+1)*((b*y)/(x+y)))+((2*l*d*b*x)/(x+y)))-l-c == 0, -x+(d*((m*x/(x+y))-(b/2)*((x/(x+y))^2)+(n*y/(x+y))-(b/2)*((y/(x+y))^2))) == 0, x, y, l )
After about 10 minutes I get the error message;
Warning: Explicit solution could not be found.
> In solve at 179
I have googled the problem and have seen other posts pointing to the use of numerical methods, but have no idea how i would write the code.
I would greatly appreciate any help on this.
Thanks, Kai
0 个评论
采纳的回答
Alan Weiss
2014-3-5
The simplest thing to do is probably not to use symbolic variables, but to use an Optimization Toolbox solver such as fmincon. In brief, you put your variables in one vector, say x, so that x(1) = your x, x(2) = your y. Then take your objective function (the thing you are trying to maximize) as fun(x), where you write a small program to return fun(x). fmincon calculates the Lagrange multipliers automatically. You can put in your positivity constraints and other constraints easily. See this basic example.
One other thing: fmincon finds a minimum. You want a maximum. So put in -fun as your function, and minimize that.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
更多回答(1 个)
Walter Roberson
2014-3-4
It appears to me that a solution does exist but that it is so long that MATLAB cannot calculate it.
You are working with 4th-order equations (quartics), and symbolic solutions to quartics are seldom profitable.
What were you planning to do with the x, y, z once you had obtained them symbolically ?
6 个评论
Star Strider
2014-3-5
Do you have the Optimization Toolbox? Alan Weiss has posted some ideas. Otherwise, consider the optimisation functions available as MATLAB core functions.
I suggest that first, you see the documentation for the solver you want to use to be sure your objective function is in a form the solver needs. Then with the Symbolic Math Toolbox, use the ‘subs’ function to convert your parameters to a subscripted parameter vector, and use ‘matlabFunction’ to convert your symbolic equations into code the solver can use.
Note that in Alan’s answer, he mentions that the solvers calculate the Lagrange multipliers, so you will have to start with your original equations, rather than the ones you posted here.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!