Hi everyone,
I'm trying to simplify an expression involving the Dot
operation in Mathematica, but I'm having some trouble getting the desired output. For example, consider the following code:
n = 3;
X = Array[x, n];
Y = Array[y, n];
f[x_, y_] = (x - y) . (x - y);
expr = D[f[X, Y], {X}];
The resulting expression ·expr· is
{2 (x[1] - y[1]), 2 (x[2] - y[2]), 2 (x[3] - y[3])}
Now, I want to obtain a result in vector form as 2 (X - Y). If there any way to do so?
If I try
expr = D[f[x, y], {x}];
Then, I obtained an expression involves the Dot
operation:
1 . (x - y) + (x - y) . 1
which is closed to my desired result, but I want to merge the two terms involving (x - y) and obtain the simplified expression 2 (x - y). Using Simplify
and FullSimplify
don't seem to work in this case.
Is there a way to get my desired expression by simplfying the Dot expression or representing the result in vector form? Thanks in advance for your help!