Tag Info

New answers tagged

5

Another way is to use ListConvolve: neighbors = ListConvolve[{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, m, {2, 2}, 0]; neighborCount = ListConvolve[{{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}, ConstantArray[1, Dimensions@m], {2, 2}, 0]; neighbors/neighborCount == MeanFilter[m, 1] True However, for speed it's not so good to go over the entire matrix in order to ...


2

My thought about recursion formula this two weeks: For recursion formula $a_{n}=c_1a_{n-1}+c_2a_{n-2}\quad (n \geq 2)$ Thanks for @IgorRivin's explanation $$ \begin{bmatrix} a_{n-1}\\ a_{n} \end{bmatrix} = \begin{bmatrix} a_{n-1}\\ c_1a_{n-1}+c_2a_{n-2} \end{bmatrix} = \begin{bmatrix} 0 & 1\\ c_2 & c_1 \end{bmatrix} \begin{bmatrix} a_{n-2}\\ ...


2

I have tried some String manipulation functions : StringCases["342121212136" , s : (x__ ~~ (x_) ..) -> {x, s}] gives the longest cycle in the string :{{2121, 21212121}} If you want the shortest cycle : StringCases["342121212136" , s : (Shortest@x__ ~~ (x_) ..) -> {x, s}] gives : {{21, 21212121}} If you are not interested in extracting cycles ...


1

To get the longest repeating subsequence and the number of its repetitions: ClearAll[rDF] rDF[a : Repeated[Longest[x__], {2, Infinity}]] := {{x}, Length[{a}]/Length[{x}]} rDF[___] := False rDF @@@ IntegerDigits[{1, 11, 212212, 2122126, 212212212212, 2122122122125}] (* {False,{{1},2},{{2,1,2},2},False,{{2,1,2,2,1,2},2},False} *) To get the shortest ...


7

An alternative to belisarius's answer f[n_] := IntegerDigits@n /. l : {x__ ..} :> {{x}, Length@l/Length@{x}} /. {_, 1} -> False f[123123] (* {{1, 2, 3}, 2} *) f[1] (* False *)


10

f[x_] := Module[ {s = IntegerDigits@x, s1}, s1 = s /. {y__ ..} :> {y}; {s1, Length@s/Length@s1}] f@212212212212 (* {{2, 1, 2}, 4}*)


6

Nice problem! Maybe something like this: repeatingdigits[n_Integer] := Module[{digits = IntegerDigits[n], res = False, div}, div = Divisors[Length[digits]]; Do[With[{z = Partition[digits, d]}, If[Equal @@ z, res = {z[[1]], Length[z]}; Break[]]], {d, Reverse[Most[div]]}]; res] repeatingdigits /@ {1, 11, 212212, 2122126} (* {False, {{1}, 2}, ...


1

It's not clear to me whether you're looking for general insight into this data or to develop specific analytical queries. But here's a barebones forest-for-the-trees graphical overview of the state changes which you could use to refine your questions, such as what metrics are relevant (eg median time to close a ticket vs number of times it's still open in ...


5

Obsolete since 1991 but ... still working and useful:) lst = {Tan, Sin, Cos, x}; Compose @@ lst (* Tan[Sin[Cos[x]]] *) or, Fold: foldF = Fold[#2[#] &, #, {##2}] & @@ Reverse@# &; foldF@lst (* Tan[Sin[Cos[x]]] *)


3

It is Composition list = {Tan, Sin, Cos, x}; (Composition @@ Most@list)@Last@list (* Tan[Sin[Cos[x]]] *)


1

Apply[Apply[Composition, Drop[%, -1]], Take[%, -1]]


11

Definition GaussCurvature[f_] := With[{dfu = D[f, u], dfv = D[f, v]}, Simplify[(Det[{D[dfu, u], dfu, dfv}] Det[{D[dfv, v], dfu, dfv}] - Det[{D[f, u, v], dfu, dfv}]^2) / (dfu.dfu dfv.dfv - (dfu.dfv)^2)^2]]; Sphere As @ ubpdqn already remarked GaussCurvature[{Cos[u] Sin[v], Sin[u] Sin[v], Cos[v]}] 1 Ellipsoid ellipsoid = {2 Cos[u] ...


6

Note this parametric surface of unit sphere (S^2) should have constant Gaussian curvature: 1. Surface: x[u_, v_] := {Cos[u] Cos[v], Cos[u] Sin[v], Sin[u]} First fundamental form: fff = FullSimplify[With[{p1 = D[x[a, b], a], p2 = D[x[a, b], b]}, {p1.p1, p1.p2, p2.p2}]]; Second fundamental form: nm = FullSimplify[Cross[D[x[a, b], a], D[x[a, b], ...


1

Another expression using Cross gaussianCurvature[r_, {u_, v_}] := Module[{n, ru = D[r, u], rv = D[r, v], ruv = D[r, u, v]}, n = Cross[ru, rv]; ((D[ru, u].n) (D[rv, v].n) - (ruv.n)^2)/(n.n)^2 // Simplify ] Examples gaussianCurvature[{Cos[u] Sin[v], Sin[u] Sin[v], Cos[v]}, {u, v}] 1


1

Ok, here's an answer to my own question based on the paper by Cheng Hian Goh, et al. There doesn't seem to be any pre-canned data structure in mathematica that supports this, perhaps it's an enhancement request for the future. Therefore this answer is really just my favorite solution so far (that doesn't involve round tripping to an external database). The ...


2

Since the Fibonacci sequence is your example you should see: Fibonacci Sequence Generator As described there you can also make use of LinearRecurrence: LinearRecurrence[{1, 1}, {1, 1}, 15] {1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610} The syntax is simple and fairly general. It is comparatively fast for generating a complete sequence ...


6

Just approaches using Nest: Fibonacci: fi[1] := 1; fi[2] := 1; fi[n_] := First@Nest[{#[[1]] + #[[2]], #[[1]]} &, {1, 1}, n - 2] Note: Timing[fi[200]] yields: {0., 280571172992510140037611932413038677189525} or (really the same): fb[1] := 1; fb[2] := 1; fb[n_] := First@Nest[{{1, 1}, {1, 0}}.# &, {1, 1}, n - 2] yields same Or ...


8

A number of points: First, if you need to compute several values of your sequence, your intial memo-ized implementation will NOT run into recursion limit problems. Second, if you need to compute very few values, this method is extremely inefficient - the $n$-th Fibonacci number (or the $n$-th term of a linear recurrence in general) can be computed in ...


1

Although I cannot understand why j in Evaluate[Table[p[0, j, u], {j, 0, n}]] = pts is Local, I use P[0, #, u] & /@ Range[0, n] to avoid using Table[p[0, j, u], {j, 0, n}] If someone know the reson,Could you tell me?Thanks sincerely:-) With the help of @kale, I improve my function deCasteljauPlot deCasteljauPlot[pts : {{_, _} ..}, u_?NumericQ, opts : ...


12

If you can rewrite the recursion to be tail recursive, you will not run into recursion limits. Here is an example of a tail-recursive implementation of factorial. factorial[1, val_: 1] = val; factorial[k_Integer /; k > 1, val_: 1] := factorial[k - 1, k val] factorial /@ Range[10] {1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800} ...


7

Set has attributes HoldFirst. So when we evaluate a=2 (aka Set[a,2]), a is held until the rhs is evaluated. In your example, the issue is setting your initial points with Table[p[0, j, u], {j, 0, n}] = pts;. We can add Evaluate and get along with our business. This forces the Table command to evaluate first before proceeding with Set. deCasteljau[pts_, u_] ...



Top 50 recent answers are included