Tag Info

New answers tagged

1

Here's one way... g[1][x_] := 1; g[2][x_] := x; g[3][x_] := x^2; norm[r_, s_] := Integrate[r[x]*s[x] + r'[x]*s'[x], {x, 0, 1}]; gram=Array[norm[g[#1], g[#2]] &, {3, 3}] or... gram=Table[norm[a, b], {a, {g1, g2, g3}}, {b, {g1, g2, g3}}]; or... gram=Outer[norm, {g1, g2, g3}, {g1, g2, g3}]


7

Here's my functional variant of your code: findSeam2[e_List] := Module[{f = FoldList[MinFilter[#1, 1] + #2 &, First[e], Rest[e]]}, Reverse@ FoldList[#1 + First@Ordering[#2[[Max[1, #1 - 1] ;; Min[Length[#2], #1 + 1]]]] - 1 - If[#1 == 1, 0, 1] &, First@Ordering[Last[f], 1], Reverse@Most[f]]]; And my test case ...


2

As suggested by @mgamer you do need memoizing. If all you care about is the flight length then you do not need the actual function, just recursively define collatzLength[1] = 0; collatzLength[n_Integer] := collatzLength[n] = 1 + If[EvenQ[n], collatzLength[n/2], collatzLength[3*n + 1]] Timing[Max[Map[collatzLength, Range[1, 1000000]]]] returns ...


3

Defining the "Collatz"-Function like you did is straight-forward, but in the sense of Mathematica not optimal. When computing the length of a Collatz-Sequence a lot of duplicate calculations are done. So defining: collatz[n_] := collatz[n] = If[EvenQ[n], n/2, 3*n + 1] prevents Mathematica from doing duplicate evaluation. This is more efficient than ...


1

it works, you just have complex functions, also the range you had was not helping. It is also better I think to use {c1, c2, c3} instead of {c1[t], c2[t], c3[t]} Clear[x, y, z, s, c1, c2, c3, t, w12, w21, w23, w23, w32, w13, w31, e0, ham] w12 = -0.001; w21 = 0.001; w13 = -1.000; w31 = 1.000; w23 = -0.999; w32 = 0.999; ham = 0.005; e0 = 9.0; paramND = ...



Top 50 recent answers are included