Tag Info

Hot answers tagged

5

I think the first few lines are self explanatory, they just build up a list of rules and wrap them in head dispatch. In this particular example the rules pertain to fitted models and particular test results but the dispatch mechanism is quite general. Basically dispatch here is a way of creating a property extraction mechanism similar in spirit to that of ...


5

E.g, function squares list elements: l1 = {1, 2, 3, 4, 5} {l1, l2, l3, l4, l5, l6} = NestList[#^2 &, l1, 5] (* {{1, 2, 3, 4, 5}, {1, 4, 9, 16, 25}, {1, 16, 81, 256, 625}, {1, 256, 6561, 65536, 390625}, {1, 65536, 43046721, 4294967296, 152587890625}, {1, 4294967296, 1853020188851841, 18446744073709551616, 23283064365386962890625}} *) This ...


3

Here is my take on it, but the code isn't really very small / simple. The algorithm Main algorithm The algorithm goes as follows: Split both lists into equivalent classes under sorting of inner lists. For each of outer lists, we will obtain a nested list of groups, and within each group, sublists will be equivalent modulo permutations. Group together ...


3

According to the documentation center: Goto first scans any compound expression in which it appears directly, then scans compound expressions that enclose this one. Your Goto - Label construction is part of the List so Mathematica fails to find the label. Taking this under consideration, the following will work: k = 0; Do[{ Label[top]; k = k + 1; ...


2

I think you want to define f1 as f1 = Function[u, 3 + u] since the form you started with would have created the function and then applied it to x. The easiest way to do what you want is to use Map: Map[f1, list] which has an equivalent syntax f1 /@ list If you really must use a Do loop, you would do it as follows: Module[{result = {}}, ...


2

You need to change the preset value of the WindowMargins option to Automatic. Example: CreatePalette[Row[PasteButton /@ ToExpression[CharacterRange["a", "z"]]], WindowMargins -> Automatic, WindowTitle -> "Letters"];


2

p1 = {1, 2, 3, 4, 5, 6, 7, 8}; j = {1, 6, 7, 8}; p1[[j]] *= 2; p1 (* {2, 2, 3, 4, 5, 12, 14, 16} *) Replacing your function (I assume you want to keep the argument/original unchanged and return the changed version): p1 = {1, 2, 3, 4, 5, 6, 7, 8}; domul[p1_] := Module[{replacement = p1, j = {1, 6, 7, 8}}, replacement[[j]] *= 2; replacement]; ...


2

With the new Association data structure introduced in the Wolfram Language/Mathematica 10 (you can try it now on the Raspberry Pi), this becomes extremely very simple to write and lookups are highly efficient as well. property = Association@Thread[elements -> chemistry] property @> Ni (* 0.06 *)


1

There seem to be at least two issues here: You are not resetting ExtractionCon = {} inside the outer Do loop, therefore Divided1 grows longer than Partition1 With (1) corrected you will get a different error (repeated): Set::setraw: Cannot assign to raw object 3. >> because the x* Symbols now have values, and they evaluate before the assignment is ...


1

How about something like Clear[fu, fus] With[{uq = Unique["fus"]} , fu[k_] := uq[[k]]; uq = Function[{x}, #] & /@ Table[ Integrate[(x^k Sin[x])/Exp[k x^2], x] , {k, 1, 5} ] ] I picked this example because this integral does not produce a nice result for a fixed k. It can be reasonable to want to make a few functions here, as ...


1

The implementation you linked to works fine. I do not understand why you could not make it work. Verified it with Maple build-in function. Same result: LinearAlgebra[HouseholderMatrix](<1,2,3,4,5>); Mathematica: HouseholderMatrix[v_?VectorQ] := IdentityMatrix[Length[v]] - 2 Transpose[{v}].{v}/(v.v); HouseholderMatrix[{1, 2, 3, 4, 5}]; ...


1

In Mathematica: Reduce[ForAll[{x, y}, x <= y \[Equivalent] x < y + 1], Integers] (* True *) or: Resolve[ForAll[{x, y}, x <= y \[Equivalent] x < y + 1], Integers] (* True *) For a mathematical proof, the direct implication $x \leq y \Rightarrow x < y+1$ has the trivial proof noted by @rcollyer in a comment. The converse ...


1

Memory inefficient approach: RandomSample[ DeleteCases[Tuples[Range[5], {2}], {n_, n_}], 5] or alternatively with Subsets. RandomSample[Join[{##}, Reverse /@ {##}] & @@ Subsets[Range[5], {2}], 5] Time inefficient approach: list = {}; Do[ While[ While[Equal @@ ({i, j} = RandomInteger[5, 2])]; MemberQ[list, {i, ...


1

OK, I think I can give you some tips about performance here. There are a couple things you do that really tend to slow you down, and which I would describe as Mathematica "anti-patterns". In particular, building arrays by repeatedly calling AppendTo is likely to be really slow (the time taken will grow quadratically in the length of the list), and accessing ...



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