TransWikia.com

Extracting subexpressions

Mathematica Asked on January 17, 2021

This is a recurrent topic: replacing subexpressions. See for instance:

v = {v1, v2, v3};
expr = v/Norm[v] // Simplify[#, Assumptions -> _ [Element] Reals] &

(* {v1/Sqrt[v1^2 + v2^2 + v3^2], 
    v2/Sqrt[v1^2 + v2^2 + v3^2], 
    v3/Sqrt[v1^2 + v2^2 + v3^2]} *)

Is it possible to go from the developed form of expr back to $v/|v|$?

Most solutions on this website (such as CoefficientArrays) rely on a polynomial form, which is not the case here. Specifying the rule manually (such as Sqrt[v1^2 + v2^2 + v3^2] -> n does not help, which is not surprising since Mathematica handles the expression differently from what it looks like.

This one is a simple example but of course, I would like the solution to work on more intrincated cases, such as:

{{-(v1^2/(v1^2 + v2^2 + v3^2)^(3/2)) + 1/Sqrt[v1^2 + v2^2 + v3^2],
-((v1 v2)/(v1^2 + v2^2 + v3^2)^(3/2)), -((v1 v3)/(v1^2 + v2^2 + v3^2)^(3/2))}
, {-((v1 v2)/(v1^2 + v2^2 + v3^2)^(3/2)), -(v2^2/(v1^2 + v2^2 + v3^2)^(3/2)) 
+ 1/Sqrt[v1^2 + v2^2 + v3^2], -((v2 v3)/(v1^2 + v2^2 + v3^2)^(3/2))}
, {-((v1 v3)/(v1^2 + v2^2 + v3^2)^(3/2)), -((v2 v3)/(v1^2 + v2^2 + v3^2)^(
   3/2)), -(v3^2/(v1^2 + v2^2 + v3^2)^(3/2)) + 1/Sqrt[v1^2 + v2^2 + v3^2]}}

which is equal to the much simpler
$$ dfrac{1}{|v|}Big(I_3 – dfrac{v}{|v|}otimes dfrac{v}{|v|} Big)$$

One Answer

Try this:

expr /. a_/Sqrt[v1^2 + v2^2 + v3^2] -> a/n

(* {v1/n, v2/n, v3/n}  *)

Have fun!

Answered by Alexei Boulbitch on January 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP