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

采纳的回答

Alan Weiss
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 个评论
Kai
Kai 2014-3-5
Hi Alan,
I am trying to use the Optimization Toolbox as you suggested, but my coding ability is preventing me from progressing.
I really have never used matlab before. Please could you help me set up the optimization problem in the toolbox?
Do I need to use syms at the start to define my variables and then define my objective function and constraint in two separate editors? And then use the toolbox?
Best wishes, Kai

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
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
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!

Translated by