0
$\begingroup$

When I evaluate my Mathematica code I get out a term of the following form: $\sqrt{1+\frac{y^2}{x^2}}$. However, I also have $\sqrt{x^2+y^2}$ terms that I would like it to cancel with.

For example, I would like the following to simplify:

u[x_, y_, z_, t_] := (-2 Sqrt[x^2 + y^2] - ((1 - E^(-x^2 + y^2)) y)/x)/Sqrt[1 + y^2/x^2]

I have tried using FullSimplify, but that has got me nowhere. I also tried using Replace but can't get it to work.

Can anybody help me out? Or has anybody had a similar problem?

$\endgroup$
1
  • $\begingroup$ FullSimplify[(-2 Sqrt[x^2+y^2]-((1-E^(-x^2+y^2)) y)/x)/Sqrt[1+y^2/x^2],Assumptions->_\[Element]Reals]? $\endgroup$
    – yode
    Commented Jun 24, 2016 at 11:12

2 Answers 2

2
$\begingroup$

Just give (Full)Simplify its assumptions in the second argument, for example:

Simplify[u[x,y,z,t], {x > 0, y > 0}]

(* -2 x + ((-E^x^2 + E^y^2)*y)/(E^x^2*Sqrt[x^2 + y^2]) *)
$\endgroup$
1
  • $\begingroup$ Thank you, and you answered my question. What you've made me realise though, is that I can't assume values of x and y - something I should have realised earlier. $\endgroup$ Commented Jun 25, 2016 at 9:32
2
$\begingroup$

Try this:

expr1 = (-2 Sqrt[x^2 + y^2] - ((1 - E^(-x^2 + y^2)) y)/x)/
  Sqrt[1 + y^2/x^2];

then

expr2 = MapAt[HoldForm, expr1, {2, 1, 2, 2}] // 
   Simplify[#, {x > 0, y > 0}] & // ReleaseHold

(*  (-y + E^(-x^2 + y^2) y - 2 x Sqrt[x^2 + y^2])/Sqrt[x^2 + y^2]  *)

Take care that the assumptions x>0 and x<0 give different results.

Have fun!

$\endgroup$

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.