Tag Info

New answers tagged

1

I think this does what you're after (to be honest, I had some trouble deciphering the question). patchedData = Module[{gb = GatherBy[SortBy[#, First], First], lens, tot = 0, cnt = 1, mems = {}, sets}, lens = Length /@ gb; sets = Append[Reap[ Scan[(tot += #; mems = {mems, cnt++}; If[tot >= 12, Sow[Flatten@mems]; ...


4

This isn't a problem you should try to solve automatically. Use good code hygiene and make sure you don't call private functions. You should (aim to) understand your code well enough that you don't get surprises like this --- you wrote it, and you know it better than anyone else. If there are surprises even to you, how will anyone else understand it?! ...


0

Let me refer to the second IndicesFromStrings as IndicesFromStrings2. To make it work, replace Set[ReleaseHold[ToExpression[#1]], ToString[First@#2]] with Clear[#1]; Set[Evaluate@ToExpression[#1], First@#2], i.e. IndicesFromStrings2[ls_List, opts:OptionsPattern[]] := ( Clear[#1]; Set[Evaluate@ToExpression[#1], First@#2] ) & ~MapIndexed~ ( ...


0

Using Sort incorrectly Sorting mathematical expressions without numeric conversion New users are often baffled by the behavior of Sort on lists of mathematical expressions. Though this is covered in the documentation of Sort itself they expect that expressions will be ordered by numeric value but they are not. Instead expressions are effectively ordered ...


4

Symbols are created at the instant that they are read -- not when they are evaluated. In the first example, there are two expressions: Needs[...]; and myProgramF[...]. The first expression is read and evaluated, loading the package. The second expression is then read, resolving myProgramF using the loaded package. It is then evaluated. In the second ...


1

A mild refactoring of ubpdqn's code: f[n_, d_] := #*Map[{-Cos[#], -Sin[#]} &, #/d] & @ Sqrt @ Range @ n di[n_, d_, rad_] := Module[{fu, pt, grad, pg}, fu = f[n, d]; pt = MapIndexed[{Disk[#, rad], Sqrt[HoldForm @@ #2] ~Style~ Black ~Text~ #} &, fu]; grad = Reverse[{{0, 0}, ##} & @@@ Partition[fu, 2, 1]]; pg = ...


2

Try this: Clear["Global`*"]; m = 1; \[HBar] = 1; k = 1; V = -k/Sqrt[1 + x^2 + y^2]; A = 8; \[CapitalDelta] = 10^-3; SE[Etr_] := -\[HBar]^2/(2 m) \!\( \*SubsuperscriptBox[\(\[Del]\), \({x, y}\), \(2\)]\(\[Psi][x, y]\)\) + V \[Psi][x, y] - Etr \[Psi][x, y] == 0 \[CapitalOmega] = Disk[{0, 0}, A]; BC = DirichletCondition[\[Psi][x, y] == ...


11

I appreciate that attempts should be the minimum standard. As this does not resemble the desired result, perhaps it can be a starting point. I look forward to OP attempt and other answers. f[n_, d_] := Module[{r = Range@n, a}, a = Sqrt[#]/d & /@ r; MapThread[#1 {-Cos[#2], -Sin[#2]} &, {Sqrt[r], a}]] di[n_, d_, rad_] := Module[{fu, pt, grad, pg}, ...


8

adjmat = {{0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, {1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, ...


3

Here is a very simple version of what you seem to be looking for. First I enter some fake data: points = {{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 1}, {0, 0, 1}, {0, 1, 0}}; am = {{0, 1, 0, 0, 1, 0}, {1, 0, 0, 0, 1, 0}, {0, 0, 0, 1, 0, 1}, {0, 0, 1, 0, 0, 1}, {1, 1, 0, 0, 0, 0}, {0, 0, 1, 1, 0, 0}}; i.e. points (their coordinates) and adjacency ...


1

Fourth fork of the list of links. Manipulate/Dynamic Got Manipulate? (Seminar slides) Manipulate secrects revealed What is the equivalent of a prototypical Manipulate in lower level functions? Selective evaluation of blocks of code in a Manipulate Understanding CDF How to modularize custom controls for Manipulate? ...


4

It seems that the built-in FindPath greatly outperforms István's findPaths. Replace the line findPaths[g, l, mu] with FindPath[g, l, mu, Infinity, All]. On your test case, both methods return the same answer. l = {7, 5, 3, 2, 1, 1, 0, 0}; mu = {2, 2, 1, 0, 0, 0, 0, 0}; w = {3, 2, 2, 1, 1, 1, 1, 1, 1, 1}; Timing[oldFindGTPatternsN[l, mu, w]][[1]] % 65.567220 ...


5

Based on this article: kylen314.com/archives/1647 st = Import[ "http://mp.weixin.qq.com/s?__biz=MzA5NDY3OTAyNA==&mid=205311623&\ idx=1&sn=7b565a6ed5789732f698d5a6b4c5c652&scene=2&from=timeline&\ isappinstalled=0#rd", "XMLObject"]; PicAddress = Cases[st, XMLElement["img", {"data-src" -> src_, ___}, {}] :> src, {0, ...


2

Yes: Just use return MLPutFunction(mlp, "EvaluatePacket", 1L) && MLPutFunction(mlp, "ToString", 1L) // <<<--- ! && MLPutFunction(mlp, "ToExpression", 1L) /* ... */


2

This is a question of finding a suitable algorithm rather than use of Mathematica. The challenge is to generate only the permutations that will be used, rather than generate all permutations and filter those that satisfy a criterion. Fun problem. Here's my solution: cond = {0, 0, 1}; possibleElements = Range[cond, Length@cond-1]; (* {{0, 1, 2}, {0, 1, ...


2

This is pretty functional: f = Module[{comps, r = Reverse@Range[#2, #1 - 1]}, comps[l1_, l2_] := Join @@ Map[Thread[{Sequence @@ #, Complement[l2, #]}] &, l1]; Reverse /@ Fold[comps, Transpose@{First@r}, Rest@r]] &; This is about 10-15% faster, very slightly higher memory use (but still far below your current solution): fz = With[{r = ...


2

pdata[[Flatten[ Values[Map[{#[[1]], #[[-1]]} &, PositionIndex[pdata[[;; , 1]]]]]]]] (*{{AA, 1, 10}, {AA, 2, 20}, {CC, 3, 30}, {CC, 7, 70}, {DD, 8, 80}, {DD, 10, 100}, {EE, 11, 110}, {EE, 13, 130}, {HH, 14, 140}, {HH, 20, 200}}*)


3

You can also use the Version 10 functions GroupBy and Merge: Join@@Values@GroupBy[pdata, First, Through@{First,Last}@#&] and Join@@Values@Merge[#->{##}&@@@pdata,Through@{First,Last}@#&] to get (* {{AA, 1, 10}, {AA, 2, 20}, {CC, 3, 30}, {CC, 7, 70}, {DD, 8, 80}, {DD, 10, 100}, {EE, 11, 110}, {EE, 13, 130}, {HH, 14, 140}, {HH, 20, ...


3

If you data is sorted: Flatten[SplitBy[pdata, #[[1]] &][[All, {1, -1}]], 1] if not: Flatten[GatherBy[pdata, #[[1]] &][[All, {1, -1}]], 1]



Top 50 recent answers are included