# Solving system of equations from partial derivatives & Lagrange multipliers

GROUPS:
 I'm trying to solve a system of equations using the following code: Solve[(x11/theta11) == lambda1 + (lambda3*pi1) && (x12/theta12) ==      lambda1 + (lambda3*pi2) && (x13/p1) == lambda3 && (x21/theta21) ==      lambda2 + (lambda4*pi1) && (x22/theta22) ==      lambda2 + (lambda4*pi2) && (x23/p2) ==      lambda4 && (x11/pi1) + (x21/pi1) == (lambda3*theta11) + (lambda4*      theta21) && (x12/pi2) + (x22/pi2) == (lambda3*      theta12) + (lambda4*theta22) && theta11 + theta12 == 1 &&   theta21 + theta22 == 1 && (theta11*pi1) + (theta12*pi2) + p1 ==    1 && (theta21*pi1) + (theta22*pi2) + p2 == 1, {theta11, theta12,   theta21, theta22, pi1, pi2, p1, p2, lambda1, lambda2, lambda3,   lambda4}]The code has been running for over 24 hrs, so I'm assuming there's something wrong. The system of equations arises by taking the partial derivatives of each theta, pi, p, and lambda variable using the following code: D[x11*Log[theta11*pi1] + x12*Log[theta12*pi2] + x13*Log[p1] +     x21*Log[theta21*pi1] + x22*Log[theta22*pi2] + x23*Log[p2] -     lambda1*(theta11 + theta12 - 1) -     lambda2*(theta11*pi1 + theta12*pi2 + p1 - 1) -     lambda3*(theta21 + theta22 - 1) -   lambda4*(theta21*pi1 + theta22*pi2 + p2 - 1), theta11]for each theta, pi, p, and lambda variable. Essentially, I'm trying to find parameter values that yield the maximum of the function under certain conditions, so I'm taking the partial derivatives with Lagrange multipliers, then solving the system of equations.Does anyone see any reason why the above Solve[] code would not run properly? Any suggestions on what else I can do to solve this problem? Any help is appreciated. Thanks!
4 years ago
5 Replies
 Hello and welcome to the Wolfram Community! Please take a few minutes to read this tutorial about correct posting – especially of Mathematica code:How to type up a post: editor tutorial & general tipsIf you will not follow the tutorial, other members of community may not be able to test your code. To edit your post – click “Edit” in the lower right corner of your post. You can also attach a notebook.
4 years ago
 Bill Simpson 2 Votes Several of your variables are linear combinations of other variables. Eliminating some variables may greatly increase the speed of solutions.This Reduce[Eliminate[(x11/theta11) == lambda1 + (lambda3*pi1) &&  (x12/theta12) == lambda1 + (lambda3*pi2) && (x13/p1) == lambda3 &&  (x21/theta21) == lambda2 + (lambda4*pi1) &&  (x22/theta22) == lambda2 + (lambda4*pi2) && (x23/p2) == lambda4 &&  (x11/pi1) + (x21/pi1) == (lambda3*theta11) + (lambda4*theta21) &&  (x12/pi2) + (x22/pi2) == (lambda3*theta12) + (lambda4*theta22) &&  theta11 + theta12 == 1 && theta21 + theta22 == 1 &&  (theta11*pi1) + (theta12*pi2) + p1 == 1 &&  (theta21*pi1) + (theta22*pi2) + p2 == 1, {p1, p2, theta11, theta21, lambda2}], {theta12, theta22, pi1, pi2, lambda1, lambda3, lambda4}]returns in a few seconds a long list of various alternative solutions, depending on values of some parameters.Perhaps you can look through those alternatives, possibly dismiss many of those, and select your solution.From that you can then reconstruct the values of the eliminated variables, if necessary.Alternately, if you know that some of your variables are not zero, for example, you can provide that informationto Reduce and it will automatically eliminate alternatives that do not satisfy these conditions.