Tag Info

Hot answers tagged

18

I know this has been answered already on this site, but I cannot seem to find it. Map and Apply do subtly different things. For example, Map[f, {a,b,c}] (* {f[a], f[b], f[c]} *) If you have a list that is more deeply nested, without using the third argument which is for level specification, you get Map[f, {{a,b}, {c}}] (* {f[{a,b}], f[{c}]} *) or, if ...


18

One way would be to redirect all messages issued by ToExpression to a string-stream. Here is an example of that approach, with minimal error-checking: Needs["Developer`"] interpret[str_String] := Module[{s = StreamToString[], r, m} , Block[{$Messages = {s}}, r = ToExpression[str, InputForm, HoldComplete]] ; m = StringFromStream[s] ; Close[s] ; ...


9

The Notation package is not necessary to use an infix form of \[Star] as that is handled automatically. Also I recommend PadRight for constructing your expression (reference Generating a matrix using sublists A and B n times). SetAttributes[Star, HoldFirst] Star[a_List, n_Integer] := PadRight[a, n*Length@a, a] {1, 2}⋆5 (* ⋆ is \[Star] *) {1, 2, ...


7

Unevaluated@Sequence[1, 2]~ConstantArray~10 $\ $ {1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2} Or using Notation << Notation` Notation[ParsedBoxWrapper[ RowBox[{ RowBox[{"[", "const_", "]"}], "\[Star]", "reps_"}]] \[DoubleLongRightArrow] ParsedBoxWrapper[ RowBox[{ RowBox[{"Unevaluated", "@", RowBox[{"Sequence", "[", "const_", ...


6

Brief? How about this. Define: c = ConstantArray; Now you can get what you want using the infix notation: "a"~c~7 and 10~c~7 With lists {1, 2}~c~7 you'll need to Flatten.


5

In 10.2 there is WolframLanguageData. As a sample, to get a list (sorted by common-ness) of symbols which do not begin with $, are not *Box or *Data functions, are not solely options to other functions, and having got rid of some of the display-only things like AngleBracket: dat = WolframLanguageData[ All, {"CanonicalName", "Frequencies", ...


5

Simon's code CreateDialog[ {(a = RandomInteger[BernoulliDistribution[0.1], {200, 200}]; Dynamic[ Image[a = 1 - Unitize[(# - 3) (# - 12) (# - 13)] &@ ListConvolve[{{1, 1, 1}, {1, 10, 1}, {1, 1, 1}}, a, {2, 2}, 0]]]), DefaultButton[]}, Modal -> True]


4

I'd allow myself some guesswork here, that you're going after alternatives as a form of excercise in Mathematica programming. However, you've clearly stated, that the list is list={a, b, c, d, e, f, g, h, i, j, k, l} and the expected output is c + e + g Note, that in the question you've linked, ReplaceList and FoldList are utilized to generate lists of ...


4

There was a wrong bracket in F. Also do not use { as a normal bracket, and second you wrote Exp{[ which has to be either {Exp[ or (Exp[ . F[k1_, k2_, λ1_, λ2_, δ_, w1_, w2_] := (1 - Exp[-(w1/λ1)^k1]) (1 - Exp[-(w2/λ2)^k2]) (Exp[(1 - (1 - Exp[-(w1/λ1)^k1]))^(-δ) + (1 + (1 - Exp[-(w2/λ2)^k2]))^-δ]^(1/-δ))


1

No spacebar ... CreateDialog[ {a = Polygon[{{1, 0}, {0, Sqrt[3]}, {-1, 0}}]; Dynamic[ First@{Graphics[a = Rotate[a, 2 Pi/100], PlotRange -> {{-2, 2}, {-1, 3}}], Pause[1/100];}], DefaultButton[]}, Modal -> True]


1

To use Put or PutAppend with a filename saved in a string in terminal, one can use it in input form rather then >> or >>>, that is: filename="newfile.txt" Put[expression,filename] or PutAppend[expression,filename] I found the answer in http://stackoverflow.com/questions/8853676 by Brett Champion. While this solves my problem, I would ...



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