0
$\begingroup$

The following formula is given:

Clear["Global`*"]
expr = EuclideanDistance[{m, 2 Sqrt[m]}, {5, 0}]
eqn = Assuming[Element[{x, y, m}, Reals], Simplify[expr]]

Where m>=0,

  1. How to make the calculated (sqrt (m)) ^ 2==m, and display the results in Abs (m) after the software calculation.The result should be:
Sqrt[(-5 + m)^2 + 4 m]
  1. How to formula the polynomial in the quadratic root of the final result to get the final result:
Sqrt[16 + (-3 + m)^2]

Update 1:

Clear["Global`*"]
CompleteTheSquare::notquad = 
  "The expression is not quadratic in the variables `1`";
CompleteTheSquare[expr_] := CompleteTheSquare[expr, Variables[expr]]
CompleteTheSquare[expr_, Vars_Symbol] := 
 CompleteTheSquare[expr, {Vars}]
CompleteTheSquare[expr_, Vars : {__Symbol}] := 
 Module[{array, A, B, C, s, vars, sVars}, 
  vars = Intersection[Vars, Variables[expr]];
  Check[array = CoefficientArrays[expr, vars], Return[expr], 
   CoefficientArrays::poly];
  If[Length[array] != 3, Message[CompleteTheSquare::notquad, vars]; 
   Return[expr]];
  {C, B, A} = array; A = Symmetrize[A];
  s = Simplify[1/2 Inverse[A] . B, Trig -> False];
  sVars = Hold /@ (vars + s); A = Map[Hold, A, {2}];
  Expand[A . sVars . sVars] + Simplify[C - s . A . s, Trig -> False] //
    ReleaseHold]
Sqrt[25 - 6 m + m^2] /.   Sqrt[e_] :> Sqrt[CompleteTheSquare[e, m]]

Update 2:

Clear["Global`*"]
expr = EuclideanDistance[{m, 2 Sqrt[m]}, {5, 0}]
eqn = Refine[Simplify[expr], Assumptions -> {m >= 0}]
CompleteTheSquare::notquad = 
  "The expression is not quadratic in the variables `1`";
CompleteTheSquare[expr_] := CompleteTheSquare[expr, Variables[expr]]
CompleteTheSquare[expr_, Vars_Symbol] := 
 CompleteTheSquare[expr, {Vars}]
CompleteTheSquare[expr_, Vars : {__Symbol}] := 
 Module[{array, A, B, C, s, vars, sVars}, 
  vars = Intersection[Vars, Variables[expr]];
  Check[array = CoefficientArrays[expr, vars], Return[expr], 
   CoefficientArrays::poly];
  If[Length[array] != 3, Message[CompleteTheSquare::notquad, vars]; 
   Return[expr]];
  {C, B, A} = array; A = Symmetrize[A];
  s = Simplify[1/2 Inverse[A] . B, Trig -> False];
  sVars = Hold /@ (vars + s); A = Map[Hold, A, {2}];
  Expand[A . sVars . sVars] + Simplify[C - s . A . s, Trig -> False] //
    ReleaseHold]
eqn /.   Sqrt[e_] :> Sqrt[CompleteTheSquare[e, m]]
$\endgroup$
3
  • 2
    $\begingroup$ If you can assume $m>0$, then use depress or ResourceFunction["CompleteTheSquare"] from here. E.g. Sqrt[25 - 6 m + m^2] /. Sqrt[e_] :> Sqrt[ResourceFunction["CompleteTheSquare"][e, m]] $\endgroup$
    – Michael E2
    Mar 14, 2023 at 23:56
  • $\begingroup$ Refine[Expand[Sqrt[x^2] + Sqrt[y^2]], Assumptions -> x >= 0, Assumptions -> y >= 0]How to set the range of multiple parameters? The result of y after this setting is incorrect. How to set it? $\endgroup$
    – csn899
    Mar 15, 2023 at 0:34
  • $\begingroup$ Sqrt[25 - 6 m + m^2] /. Sqrt[e_] :> SqrtThis is mainly the replacement $\endgroup$
    – csn899
    Mar 15, 2023 at 7:01

0

Browse other questions tagged or ask your own question.