Group Abstract Group Abstract

Message Boards Message Boards

0
|
520 Views
|
5 Replies
|
7 Total Likes
View groups...
Share
Share this post:

How to complete the square for a specific part of an expression?

Posted 1 month ago
16/((-4 + m)^2 + 4 m^2) == 16/(64/5 + 5 (-(4/5) + m)^2)

Example1:For the equation above, how can we manipulate it to complete the square in the denominator of the left-hand fraction and obtain the right-hand side?

2 Sqrt[4 - 16/((-4 + m)^2 + 4 m^2)] == 
 2 Sqrt[4 - 16/(64/5 + 5 (-(4/5) + m)^2)]

Example2:How can one complete the square in the denominator of the fractional expression inside the radical on the left-hand side so as to obtain the expression on the right-hand side?

(4 (12 - 8 m + 5 m^2))/(16 - 8 m + 5 m^2) == (
 4 (44/5 + 5 (-(4/5) + m)^2))/(64/5 + 5 (-(4/5) + m)^2)

Example3:For the equation above, since both the numerator and the denominator of the left-hand expression can be completed-square, how can one simultaneously complete the square in both the numerator and the denominator to obtain the form shown on the right-hand side?

In other words, how can the left-hand expression be transformed into the completed-square form shown on the right-hand side using Mathematica code?

POSTED BY: Wen Dao
5 Replies

Maybe because you apply it to something that is not a polynomial. Here is a way for Mathematica to automatically find the polynomial inside the expression:

findAndSquareComplete[expr_, var_] := expr /.
   (poly_ /; Exponent[poly, var] == 2) :> 
    squareCompletion[poly, var];
findAndSquareComplete[2 Sqrt[4 - 16/
     ((-4 + m)^2 + 4 m^2)], m]
POSTED BY: Gianluca Gorni
Posted 25 days ago
(4 (12 - 8 m + 5 m^2))/(16 - 8 m + 5 m^2)

It doesn't work on this.

POSTED BY: Wen Dao

Hmmm, it seems that Exponent does not check for polynomiality, unlike CoefficientList. We need a test for that:

squareCompletion[pol_, var_] /;
   PolynomialQ[pol, var] && Exponent[pol, var] == 2 := 
  Module[{var0, x}, var0 = SolveValues[D[pol, var] == 0, var][[1]];
   Collect[pol /. var -> var0 + x, x] /. x -> var - var0];
findAndSquareComplete[expr_, var_] := expr /.
   (poly_ /; PolynomialQ[poly, var] && Exponent[poly, var] == 2) :> 
    squareCompletion[poly, var];
findAndSquareComplete[(4 (12 - 8 m + 5 m^2))/(16 - 8 m + 5 m^2), m]
POSTED BY: Gianluca Gorni

You can use ResourceFunction["CompleteTheSquare"], or this imitation of mine:

squareCompletion[pol_, var_] /; Exponent[pol, var] == 2 :=
 Module[{var0, x},
  var0 = SolveValues[D[pol, var] == 0, var][[1]];
  Collect[pol /. var -> var0 + x, x] /. x -> var - var0]
POSTED BY: Gianluca Gorni
Posted 26 days ago

Why does the polynomial remain unchanged after using this function?

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