Felipe Jiménez
Felipe Jiménez

Reputation: 505

How do I get Mathematica not to multiply a vector by a scalar elementwise, but leave it as the scalar times the vector

In Mathematica I have the variable u defined as follows:

u = {1,2,3}

Now I want the product a*u to show as:

a {1,2,3}

but a*u returns this:

{a,2 a,3 a}

I have tried HoldForm and other things, but I cannot make it work. Any help?

Upvotes: 1

Views: 31

Answers (1)

Chris Degnen
Chris Degnen

Reputation: 8655

u = {1, 2, 3};

a u

{a, 2 a, 3 a}

s = Inactivate[a u]

a {1, 2, 3}

Activate[s]

{a, 2 a, 3 a}

InputForm[s]

Inactive[Times][a, {1, 2, 3}]

Upvotes: 1

Related Questions