Message Boards Message Boards

0
|
5855 Views
|
6 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Solve the function 2 x + 4 y - x^2 - y^2 in Mathematica

Posted 4 years ago

Hi;

How can I solve the function 2 x + 4 y - x^2 - y^2 in Mathematica. I have tried several Mathematica commands and none seem to solve this particular problem. The key to solving this problem is completing the squares which produces the answer x=1 and y=2. Solving the problem manually is fairly easy, but I would like to solve it in Mathematica.

Thanks so much,

Mitch Sandlin

POSTED BY: Mitchell Sandlin
6 Replies

There are other solutions.

In[11]:= Solve[(2 x + 4 y - x^2 - y^2 /. x -> 2) == 0]

Out[11]= {{y -> 0}, {y -> 4}}

Could specify that real solutions are desired.

In[12]:= Solve[2 x + 4 y - x^2 - y^2 == 0, {x, y}, Reals]

During evaluation of In[12]:= Solve::svars: Equations may not give solutions for all "solve" variables.

Out[12]= {{y -> 
   ConditionalExpression[2 - Sqrt[4 + 2 x - x^2], 
    1 - Sqrt[5] < x < 1 + Sqrt[5]]}, {y -> 
   ConditionalExpression[2 + Sqrt[4 + 2 x - x^2], 
    1 - Sqrt[5] < x < 1 + Sqrt[5]]}, {x -> 1 - Sqrt[5], 
  y -> 2 - Sqrt[4 + 2 (1 - Sqrt[5]) - (1 - Sqrt[5])^2]}, {x -> 
   1 + Sqrt[5], y -> 2 - Sqrt[4 + 2 (1 + Sqrt[5]) - (1 + Sqrt[5])^2]}}
POSTED BY: Daniel Lichtblau

David Park's Presentations add-on applications provides a function to do this:

    << Presentations`

    CompleteTheSquare[2 x + 4 y - x^2 - y^2, x]
(* 1 - (-1 + x)^2 + 4 y - y^2 *)

    CompleteTheSquare[%, y]
(* 5 - (-1 + x)^2 - (-2 + y)^2 *)
POSTED BY: Murray Eisenberg

You can complete the squares with a replacement rule, like this:

2 x + 4 y - x^2 - y^2 //. a_*u_ - u_^2 :> -(u - a/2)^2 + a^2/4
POSTED BY: Gianluca Gorni

Check the three alternatives in the file. There are many solutions if z (the right part side) is positive (or Integer).

Attachments:

Hi Christos;

Knowing what the function is equal to is part of the problem. It is actually equal to 5 but you don't know that until you complete the squares. Once you know the function equals 5, you can plug the function into Solve[] and get the answer.

Thanks,

Mitch Sandlin

POSTED BY: Mitchell Sandlin

Mitchell, You need to formulate it correctly. Is that equal to zero? Any bounds?Only 1 equation with two variables?

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract