# Tag Info

13

Your question is not well specified for several reasons: Pure functions accept a flexible number of arguments #1 + #2 &[a, b, c, d] a + b It is common for some arguments to not be used: #1 + #3 & @@ {a, b, c, d} a + c SlotSequence includes all arguments after the given position: +##3 & @@ {a, b, c, d} c + d Without ...

13

Let's start by taking a look at the compiled form of one of our queries: DatasetCompileQuery[Query @ First @ spans] (* DatasetWithOverrides@*Checked[Slice[205 ;; 313], Identity] *) We can see that the operation is not implemented directly in terms of part. Indeed, there are three components: DatasetWithOverrides, GeneralUtilitiesChecked and ...

12

The separation-of-variables solution you quoted has two indices appearing in it: n and j (the subscripts of the coefficient $A_{nj}$). Here, n is azimuthal mode order, i.e. it counts the number of nodes along the direction in which the polar-angle $\theta$ varies (divided by 2). The index j is needed because the wave is supposed to satisfy the boundary ...

12

It depends on what you want to do with result, but you could try like this: Function[{x}, {x, #}] /@ {1, 2} {{1, #1}, {2, #1}}

11

For full ranges There is the function DayRange that can be used for this purpose, but not in the same simple way like CharacterRange. For the days: DayName /@ DayRange[Today, Today ~DatePlus~ {{1, "Week"}, {-1, "Day"}}] {Wednesday, Thursday, Friday, Saturday, Sunday, Monday, Tuesday} For the months: DateValue[#, "MonthName"] & /@ DayRange[Today, ...

11

Using Function with a named parameter, as halmir showed, is the standard way to do this, however anything that prevents a literal Slot[1] from appearing in the body of the Function will work. Inactive as chuy showed is one possibility, but I find this cleaner: {#, Slot @@ {1}} & /@ {1, 2} {{1, #1}, {2, #1}} If the body will not be evaluated you ...

11

foo = With[{f = #0}, (# /. {p___, a, b, c, q___} :> Join[{p, "abc"}, f @ {q}])] & lst = {1, 2, a, b, c, 3, {4, a, b, c}, 5}; foo@lst (* {1, 2, "abc", 3, {4, "abc"}, 5} *) This works because With automatically renames the patterns used in RuleDelayed since both are scoping constructs. Other constructs can be used as well such as RuleDelayed itself: ...

10

Maybe something like (using Inactive): Activate[{#, Inactive[Slot][1]}] & /@ {1, 2} (* {{1, #1}, {2, #1}} *)

8

This is not an answer. It is just a very long comment. Both a simple manually operated drill press and a computer-controlled five-axis omni-mill can drill a hole through a piece of bar stock. And both will do the actual drilling in about the same amount of time. If one hole in one bar is all you want, then you will accomplish the job much faster with the ...

8

Warning: Modifying a built-in function is not advised As @m_goldberg already stated, Lookup has Attributes HoldAllComplete, so a workaround will be to remove this Attribute: Edit: As per m_goldberg's recommendation attr = Attributes[Lookup]; Attributes[Lookup] = {}; Now t1 = TempHead[a -> 1, b -> 2, c -> 3]; t2 = TempHead[c -> 3, d -> 4, ...

7

The answer is probably far from what you expect (other end of the spectrum, so to speak). As noted in a comment, for numerical linear algebra Mathematica, at some level, uses library BLAS. I believe this does not use asymptotically fast matrix products for two reasons. One is that those methods are not able, as best I recall, to take advantage of data ...

7

My first suggestion would be to localize the outer Slot, like this: With[{indx = #}, {Sin[indx], Cos[#]} & /@ list[[indx ;;]]] & /@ Range[3] (* {{{Sin[1], Cos[a]}, {Sin[1], Cos[b]}, {Sin[1], Cos[c]}}, {{Sin[2], Cos[b]}, {Sin[2], Cos[c]}}, {{Sin[3], Cos[c]}}} *) You could also rework the process to get the full set of tuples of ...

7

You can use the new (in V10) ImplicitRegion function as follows: reg = ImplicitRegion[0 <= x <= 1, {x}]; Then: ArgMax[f1[x], x ∈ reg]

7

Here is a workaround that's easy enough since it makes use of the already created Mesh region: Graphics[GraphicsComplex[ MeshCoordinates[chull], {Green, MeshCells[chull, 1], Red, PointSize[0.02], MeshCells[chull, 0], Opacity[0.6], Yellow, MeshCells[chull, 2]}]]

7

An alternative workaround is to convert the BoundaryMeshRegion into a MeshRegion from the MeshCoordinates and MeshCells. This lets you use HighlightMesh as desired: SeedRandom[0]; pts = RandomReal[4, {200, 2}]; chull = ConvexHullMesh[pts]; styles = MapThread[Style, {{0, 1, 2}, {Red, Green, Yellow}}]; fullmesh[bm_] := MeshRegion[MeshCoordinates[bm], ...

7

It seems me that the answers of mathe and Yves Klett do not meet expectations of the author. The latter is as much as I have got it, to have a short analytical expression for the solution. Probably the author has an intention to use the result further in some analytical calculations, or to do something comparable. Am I right? If yes, one should first of ...

6

As @Mr.Wizard has pointed out, your question isn't well specified. However, a pure function always needs a minimum number of arguments, otherwise an error message is thrown: #1 + #2 &[a] Function::slotn: Slot number 2 in #1+#2& cannot be filled from (#1+#2&)[a] >> a + #2 So finding the minimum number of required arguments of a pure ...

6

You can nest Functions to accomplish what I believe you want to: f = i \[Function] {Sin[i], Cos[#]} & /@ list[[i ;;]]; Array[f, 3] // Column {{Sin[1],Cos[a]},{Sin[1],Cos[b]},{Sin[1],Cos[c]}} {{Sin[2],Cos[b]},{Sin[2],Cos[c]}} {{Sin[3],Cos[c]}} This looks nicer in the Notebook: Other methods include: # /. i_ :> ({Sin[i], Cos[#]} & /@ ...

6

The docs specify that the domain should (usually) be Reals or Integers. These are keywords. You probably want the "domain" to be specified as a constraint. Maximize[{ Abs[f[{p1, p2, p3, p4, p5}, {0.5, l2}]], {p1 + p2 + p3 + p4 + p5 == 1 && p1 >= 0 && p2 >= 0 && p3 >= 0 && p4 >= 0 && p5 >= 0 ...

6

The answer is 0, if the question is what is the value of Mean[fit["FitResiduals"]] and fit is a linear, least-squares fitted model. data = WeatherData["London", "Temperature", {{2004, 1, 1}, {2013, 12, 31}, "Day"}]; normaldata = Partition[Reverse[data["Values"][[All, 1]]], 2, 1]; fit = LinearModelFit[SetPrecision[normaldata, Infinity], x, x, ...

6

Solve[L == (3 W)/2 + 3/2 Sqrt[4 A^2 Pi^2 + W^2] - Sqrt[ 6 A^2 Pi^2 + 3 W^2 + 5 W Sqrt[4 A^2 Pi^2 + W^2]]/Sqrt[2], W, Quartics -> False] or Solve[L == (3 W)/2 + 3/2 Sqrt[4 A^2 Pi^2 + W^2] - Sqrt[ 6 A^2 Pi^2 + 3 W^2 + 5 W Sqrt[4 A^2 Pi^2 + W^2]]/Sqrt[2], W, Reals]

6

Lookup has the attribute HoldAllComplete, which means the kernel evaluator will not see its arguments and, therefore, will not look at its up-values.

6

MeshFunctions, according to the documentation, "should normally be chosen to be continuous monotonic functions." Failing that, the mesh functions should be transverse to the mesh levels (i.e., cross them, not have a local extremum); in this case, however, one might have trouble with sampling missing a small region where the mesh function very briefly ...

6

Another alternative is to use ConditionalExpression using the second-order condition for a local maximum as the second argument: f = Sin; Plot[f[x], {x, 0, 20 Pi}, Mesh -> {{0}}, MeshFunctions -> {ConditionalExpression[f'[#], f''[#] < 0] &}, MeshStyle -> {PointSize[Large], Red}] f = Sin[#] - 1/2 Cos[Pi #] &; ...

5

1) Get the list of days and months. Note that days are represented in MMA as symbols (and not strings as months are), hence the use of ToString to make them in a consistent type with the list of months (credit to @Mr.Wizard for this tip). monthList=DateValue[{2014,#,1},"MonthName"]&/@Range[12] (* ...

5

is it possible to specify which range that slot takes from? The short answer is "no" (not counting solutions with named arguments since they aren't Slots) but if you really, really want to do it you can write it like I've done below, then #1 refers to the inner Map and #2 refers to the outer Map: Map[ Map[ {Sin[#], Cos[#2]} & @@ # &, ...

5

It's fun to use Associations as a circular linked list, which automatically handles the cyclic nature of these ranges: Clear@monthRange monthRange[start_, end_] := Module[{monthsLL, head}, monthsLL = Fold[ <|#2 -> #|> &, Reverse[DataPacletsCalendarDataDumpMonthList["Gregorian"] ~Join~ {monthsLL}] ]; head = ...

5

You can also use Block for this: Block[{slot = #}, {#, slot} & /@ {1, 2}] {{1, #1}, {2, #1}} This works because Block implements dynamic scoping, so the symbol slot is not replaced by #1 until slot is evaluated (i.e. after the Function has been created and mapped over the list). As pointed out by Mr. Wizard, this means that if slot is never ...

5

The commands FixedPoint and FixedPointList are rather specialized versions of Nest and NestList - both sets of commands perform functional iteration but the FixedPoint versions stop when the iterate stops changing. The *List versions return the whole computed sequence of iterates, while the non-List versions return just the last iterate. Thus, ...

5

Description ? at the beginning of a line is the short from of Information. Given a pattern that matches multiple Symbols Information returns a list of them in alphabetical (canonical) order, in columns top to bottom and left to right. You are therefore asking how you can modify the behavior of this System function. You would need some way of storing the ...

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