# dot product not working [closed]

Im supposed to take the dot product of a function and itself. The matrix is a system of 4 equations defined to be :

L[x_, y_, z_, w_] :=
{{4.0 x - 2 y + 3 z - 5 w},
{3 x + 3 y + 3 z - 8 w  },
{-6 x - y + 4 z + 3 w   },
{-4 x + 2 y + 3 z + 5 w }}


I can't take L[x,y,z,w].L[x,y,z,w] because Dot::dotsh error. I was able to successfully take the dot product earlier today but for some reason, I can't anymore.

## closed as off-topic by Szabolcs, J. M. is away♦Sep 26 '17 at 8:17

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Szabolcs, J. M. is away
If this question can be reworded to fit the rules in the help center, please edit the question.

• Is that really supposed to be a $4\times1$ matrix? If not, remove the inner braces: L[x_, y_, z_, w_] := {4.0 x - 2 y + 3 z - 5 w, (* stuff *)} – J. M. is away Sep 26 '17 at 5:02
• hi. If you do this, then the error goes way r1=L0[x,y,z,w]; r1.Transpose[r1] – Nasser Sep 26 '17 at 5:02
• Have you read the description of this error in the documentation? – Szabolcs Sep 26 '17 at 8:15

I think you are looking for this:

L[x_, y_, z_, w_] := {4.0 x - 2 y + 3 z - 5 w,
3 x + 3 y + 3 z - 8 w, -6 x - y + 4 z + 3 w, -4 x + 2 y + 3 z + 5 w}


i.e. remove the multiple curly brackets.

So that you have output

In[71]:= Dot[L[x, y, z, w], L[x, y, z, w]]

Out[71]= (-5 w + 4. x - 2 y + 3 z)^2 + (5 w - 4 x + 2 y +
3 z)^2 + (-8 w + 3 x + 3 y + 3 z)^2 + (3 w - 6 x - y + 4 z)^2


Also check out this.

The reason it worked before is that you were using plain 1-dimensional lists. Dot works well with 1D lists. Your definition of L returns a 2-dimensional list (4 rows by 1 column), which does not work (natively) with Dot .

If you do not want to change the definition of L, you can calculate the dot product using

L[a, b, c, d][[All, 1]].L[w, x, y, z][[All, 1]]


or by using

Plus @@ Apply[Times, Transpose@{L[a, b, c, d], L[w, x, y, z]}, 2]


or what amounts to the same thing,

Total@Flatten[Transpose@L[a, b, c, d]*Transpose@L[w, x, y, z]]


If you want it both ways, you can define a new L that returns a 1-dimensional list. Use the new one for calculations, since it works with Dot. When you want need the old 4x1 form, simply wrap the new form with braces and take the transpose, like this: Transpose[{new}].

• I get your point, but it's a bit confusing to say that "Dot works with 1D lists". Dot works with arbitrary dimensional tensors, contracting the last index of the first tensor with the first index of the second tensor. It's what we use for matrix products. One can't multiply a 4x1 matrix with a 4x1 matrix. – Szabolcs Sep 26 '17 at 8:13
• @Szabolcs Many thanks for pointing that out. It seems so obvious. I would fix my answer, but what more could I say than is already in the documentation, or in your comment. I agree the question is off topic. – LouisB Sep 26 '17 at 8:46
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.7367042899131775, "perplexity": 804.6002322595059}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 20, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2019-22/segments/1558232255182.37/warc/CC-MAIN-20190519221616-20190520003616-00088.warc.gz"}