Tag Info

New answers tagged

3

Consider also: Flatten @ Array[{#2, #, 1} &, {2, 2}, 0] {0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1} This is faster than Table, if applicable: n = 2200; Table[{x, y, 1}, {y, 0, n}, {x, 0, n}] // Flatten // Length // Timing Array[{#2, #, 1} &, {n, n} + 1, 0] // Flatten // Length // Timing {1.435209, 14533203} {0.280802, 14533203}


5

Table[{x, y, 1}, {y, 0, 1, 1}, {x, 0, 1, 1}] // Flatten gives {0,0,1,1,0,1,0,1,1,1,1,1}


3

The language is quite clear: If Cross is used with n arguments, all of the arguments should be vectors of length n+1. An expression is a vector if the expression is a list and none of the elements of that list are lists. This is the syntax that Cross accepts. If you want something else write your own function. Perhaps: cross[a : {{_} ..}, b : {{_} ...


2

I think this is a bug. You get the correct result from vectorAngle[vec1_, vec2_] := ArcCos[vec1.vec2/(Norm[vec1] Norm[vec2])] vectorAngle[{-2.7432000000000016`, 0.`, 0.`}, {2.743199999999973`, 0.`, 0.`}] (* ==> 3.14159 *) This function is just a manual implementation of the definition as stated in the documentation of VectorAngle. Therefore, ...


6

I believe this is one of many manifestations of machine precision arithmetic in Mathematica, and it appears because VectorAngle also works with complex values. If you use the arbitrary precision engine these cancellation errors should not occur: VectorAngle[{-2.7432`12, 0, 0}, {2.7432`12, 0, 0}] 3.14159 Note the `12 on the numbers; this sets a ...


2

Use Flatten Flatten[A] (*{a1,a2,a3,a4}*)



Top 50 recent answers are included