-1
$\begingroup$

New to Mathematica, trying to solve a simple economics problem but having troubles with using Solve and Eliminate.

The question:

Now suppose that this agent makes two choices, expressed by x and y and that these choices come at a cost x+p y. Assume the agent has 5 units of budget to cover the cost and is required to spend their entire budget, and extracts a utility given by

U[x,y]=m1 x -R1/2 x^2+ C x y+m2 y -R2/2 y^2 for C>0, m1>0, m2>0, R1>0, R2>0.

b: Define the Lagrangian for the constrained optimization problem as a function Mathematica, calculate the optimal choices of x and y as an expression in m, R, k, and C as well as the resulting utility.

My code:

enter image description here

It seems like I cannot internally get rid of the choice variables in my final answers for x, y, and lambda. Google doesn't help in this regard and I have tried Eliminate to no avail :(

I am new to Mathematica and any help would be so amazing!

Copied code:

 L(x, y, λ) =  m1 x - (R1/2) x^2 + C x y + m2 y - (R2)/2 y^2 - λ(x + p y - 5)
 
 eqn1 = Solve[ D[L[x, y, λ], x] == 0, x ]

 eqn2 = Solve[D[L[x, y, λ], x] == 0, y]
 
 eqn3 = Solve[D[L[x, y, λ], x] == 0, λ]
 
 Solve[{equation1, equation2, equation3}, {x, y, λ}, {x,    y,
 λ}]
 
 Solve[Eliminate[   x == (m1 + C y - λ)/R1 &&     y == (-m1 +
 R1 x + λ)/C && λ == 
     m1 - R1 x + C y , {x, y, λ} ]
$\endgroup$
3
  • $\begingroup$ Post copyable code, not pictures of code. $\endgroup$
    – flinty
    Commented Oct 7, 2021 at 13:31
  • $\begingroup$ To start, do not repeat {x, y, \[Lambda]}, in your fifth line of code. Also, what are you trying to accomplish by combilning Eliminate and Solve. $\endgroup$
    – bbgodfrey
    Commented Oct 7, 2021 at 13:58
  • $\begingroup$ thank you guys so much for the advice. The code looks quite unreadable and incoherent at the bottom as i realised i took a picture of this after trying all sorts of ways to play around with the code. this is my mistake. thank you for pointing it out. As for the combination of eliminate and solve, i think i was trying to replicate something i found online $\endgroup$
    – jojorabbit
    Commented Oct 7, 2021 at 15:31

1 Answer 1

1
$\begingroup$

If you are trying to solve a system of equations for a set of unknowns, you need to provide Mathematica with all of the equations at once and tell it to solve for all of the unknowns. Also note that you need to take the derivatives with respect to all three variables, not just x.

Solve[{D[L[x, y, λ], x] == 0, D[L[x, y, λ], y] == 0, D[L[x, y, λ], λ] == 0}, {x, y, λ}]

This yields a mildly complicated expression that I won't replicate here, but it does give expressions for x, y, and λ that that depend only on the parameters of the problem (and not on each other.)

Also, you have several syntax errors in your code:

  • The function you're minimizing should be written as L[x, y, λ]—or even better, L[x_, y_, λ_]—and not L(x, y, λ). Parentheses () are only for order of operations in Mathematica; arguments of functions must use square brackets [].

  • You define eqn1, eqn2, and eqn3 in your code and then refer to equation1, equation2, and equation3 below it. Mathematica does not (of course) know that these are the same thing. If it works for you, it is probably because you defined equation1, equation2, and equation3 at some point earlier in your session and the variable definitions have persisted in memory. In general, Mathematica does its calculations in a separate program called the "kernel", and the window you type things into is the "front end". Deleting definitions from the front end does not clear their definitions in the kernel. The easiest way to reset the kernel is to use the menu option Evaluation > Quit Kernel > Local.

$\endgroup$
2
  • 1
    $\begingroup$ thank you so much! i apologise for the bad code after that. I realised that the picture i sent was me trying all sorts of ways to play with the functions to make them work. i realise now that without context, it looks like it is incoherent. $\endgroup$
    – jojorabbit
    Commented Oct 7, 2021 at 15:31
  • $\begingroup$ i have had time to look through the answer and would really like to say thanks again. u were helpful and non-judgemental, and your answer is clear and understandable. thank you! $\endgroup$
    – jojorabbit
    Commented Oct 7, 2021 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.