## How to multiply a vector by a scalar?

0

I'm plotting a simple 2D graph derived from 4 3D vectors:

Subscript[A, 1]={1,0,0}
Subscript[X, 1]={0,0,1}
Subscript[A, 2]={0,1,0}
Subscript[X, 2]={1,0,1}
(* {1,0,0} *)
(* {0,0,1} *)
(* {0,1,0} *)
(* {1,0,1} *)

f =
Norm[
(Subscript[t, 1].(Subscript[A, 1] - Subscript[X, 1]) +
Subscript[X, 1] - Subscript[t, 2].(Subscript[A, 2] -
Subscript[X, 2]) - Subscript[X, 2])]^2
(* Abs[-1+Subscript[t, 1].{1,0,-1}-Subscript[t, 2].{-1,1,-1}]^2+2 Abs[Subscript[t, 1].{1,0,-1}-Subscript[t, 2].{-1,1,-1}]^2 *)


But f cannot be plotted:

ContourPlot[f, {Subscript[t, 1], 0, 1}, {Subscript[t, 2],0,0}]
(* ContourPlot[f,{Subscript[t, 1],0,1},{Subscript[t, 2],0,0}] *)


Apparently Mathematica doesn't recognize scalar dot vector or scalar space vector. So what expression should I use to define this function?

2

You've got a few glitches going on.

First you want to use times to multiply a scalar with a vector.

i.e. evaluate: s {x[1],x[2],x[3]} $\mapsto$ {s x[1], s x[2], s x[3]}

Subscripts aren't symbols so you don't want to use them as variables. It turns out you aren't assigning things to the variable you think you are, you're assigning things to the symbol Subscript. This isn't a great idea. You can always format what you want to look like Subscripts if that's what you care about.

To make things look the most like what you had written, besides getting rid of your dot products between scalars and vectors, in my rewrite of your function I'll locally redefine subscript in the $t_1$ and $t_2$ cases to map to nice easy symbols t1 and t2.

f[t1_, t2_] =
Block[{Subscript}, Subscript[t, 1] = t1; Subscript[t, 2] = t2;
Norm[(Subscript[t, 1] (Subscript[A, 1] - Subscript[X, 1]) +
Subscript[X, 1] -
Subscript[t, 2] (Subscript[A, 2] - Subscript[X, 2]) -
Subscript[X, 2])]^2];


Next problem is that your Contour plot gave no range to t2, you had it going from 0 to 0, which isn't going to be great for 2D graphics.

Let's take it from 0 to 1:

ContourPlot[f[t1, t2], {t1, 0, 1}, {t2, 0, 1}] yields:

Proof that you don't want to be assigning things to Subscript, try evaluating: DownValues[Subscript]. You are really better off either using functions like: A[1], etc, or straight symbols: A1.

yes, the 2 mistakes I made are dot VS plain multiply and range for t2. The Subscribe[ , ] are the result of copying Mathematica expression to plain text. – tribbloid – 2017-08-20T00:18:12.497

I suspect you're probably using formatted Subscripts (ctrl+_) in your notebook (which was copied here as Subscript[...]). If you are (and you want to continue doing so) you should read these two answers [ 1 ] , [ 2 ].

– John Joseph M. Carrasco – 2017-08-20T00:36:33.850