# Tag Info

9

How about this furious[a_, b_] := Module[{a1, a2, a3, b1, b2, b3, c}, {a1, a2, a3} = Transpose[a, {2, 3, 4, 1}]; {b1, b2, b3} = Transpose[b, {2, 3, 4, 1}]; c = {-a3 b2 + a2 b3, a3 b1 - a1 b3, -a2 b1 + a1 b2}; Transpose[c, {4, 1, 2, 3}]] Timing results (from march's answer) for version 10.4.1 list1 = RandomReal[{-1, 1}, {32, 32, 32, 3}]; list2 = ...

7

Interestingly enough, MapThreading Cross works but is much slower: Using sample lists: list1 = Array[c, {20, 20, 20, 3}]; list2 = Array[d, {20, 20, 20, 3}]; We can perform this operation in the following two ways, using MapThread: listCrossMarch1[list1_, list2_] := MapThread[Cross, {list1, list2}, 3] listCrossMarch2[list1_, list2_] := MapThread[{#1[[2]] ...

4

One can use the new function DistanceMatrix[] for the purpose; this avoids repeated computations (since the underlying matrix is symmetric). With[{stepSize = 2, end = TMax}, MatrixPlot[UnitStep[0.01 - DistanceMatrix[uSolpbc[Range[0, end, stepSize], 0]]]]] and your plot is produced very quickly, without the need to invoke parallelization.

2

I have experienced serious memory leaks with NDSolve, NIntegrate, and FindRoot in every version of Mathematica I have owned (still on V9), perhaps over 20 years. They typically show up for me when the routine is called at a deep level in a complex program. The only cure in many cases is to remove the offending routine and write your own. For NIntegrate, ...

2

The plot in the question must have been obtained with stepSize = 15, not stepSize = 2. Using the latter value gives a smooth plot, The computation takes about 78 sec on my PC. To address the specific issue in the question, the run time can be reduced by two orders of magnitude using Block[{stepSize = 2, end = TMax, tt, rd}, tSolpbc = Table[uSolpbc[...

2

Here, I will use LibraryLink technique to calculate the nonzero B-spline basis. About the C code, please see happy fish's revision. Firstly, I make a comparison with optimizedNonzeroBasis[], compiledNonzeroBasis[] and librarylinkNonzeroBasis[]. knots0 = Join[ConstantArray[0, 3001], Range[1, 5000], ConstantArray[5001, 3001]]; deg0 = 3000; i = 3002; ...

1

Here is a solution via the Wolfram LibraryLink technique: First, let us make a comparison between BezierNonzeroBasis[n, u] and BernsteinBasis[n, Range[0, n], u] Do[BezierNonzeroBasis[10, 0.1], {10000}] // AbsoluteTiming Do[BernsteinBasis[10, Range[0, 10], 0.1], {10000}] // AbsoluteTiming BezierNonzeroBasis[10000, 0.1]; // AbsoluteTiming ...

Only top voted, non community-wiki answers of a minimum length are eligible