# 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

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 ...

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 ...

13

I believe this is correct, and very fast: fn[x_Integer, n_Integer] := Complement[Range @ x, Join @@ Range[#, x, #]] & @ Prime @ Range @ n Test: fn[10000, 1223] {1, 9929, 9931, 9941, 9949, 9967, 9973} It seems I am a bit late to return to this problem and Simon Woods already provided a memory optimized approach. His sieve is comparatively ...

13

This is competitive with Mr Wizards code and seems faster in some cases: fn2[x_Integer, n_Integer] := Module[{y = Range @ x}, (y[[# ;; x ;; #]] = 0) & /@ Prime[Range @ Min[n, PrimePi @ x]]; SparseArray[y]["NonzeroValues"]] AbsoluteTiming[fn[10000, 1223];] (* {0.004000, Null} *) AbsoluteTiming[fn2[10000, 1223];] (* {0.010001, Null} *) ...

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: ...

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, ...

9

Here's what the plot looks like: f[x_] := x^3 g[x_] := x^5 - 2 x^3 - 3 x Plot[{f[x], g[x]}, {x, -5, 5}, PlotRange -> {-10, 10}] You first solve for the intersections: sol = x /. NSolve[f[x] == g[x], x, Reals] {-1.94712297, 0, 1.94712297} Now you can find the area by integrating the difference between the curves in the intervals obtained: ...

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

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

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 ...

7

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 #] &; ...

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

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

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 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

Here I post a different approach based on the awesome new Region functions: f[x_] := x^3 g[x_] := x^5 - 2 x^3 - 3 x We solve for the intersections: sol = x /. NSolve[f[x] == g[x], x, Reals] {-1.94712297, 0, 1.94712297} Edit Here are the regions of interest: r1 = ImplicitRegion[g[x] > y && f[x] < y, {{x, -1.94712297, 0}, y}]; r2 = ...

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

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

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 ...

4

Setting b = 1 from the start, your equation can be rewritten as (3 k)/(3 + a k^2) == Tan[k] This has multiple solutions for k for any given value of a. Here's e.g. the plot of the LHS and the RHS for a = 1; the intersections are the solutions: Plot[ { (3 k)/(3 + k^2), Tan[k] }, {k, -10, 10}, Exclusions -> Tan[k] == 0, PlotPoints -> 500 ] ...

4

From the comments, we can set up the OP's DEs as follows and show they can be solved exactly. First the system is the direct product of two independent systems, so let's separated them. γ = 6; g = -98/10; yIVP = {y''[t] + γ*(y'[t])^2 == g, y[0] == 0, y'[0] == 15/10}; qIVP = {q''[t] == -γ*(q'[t])^2, q[0] == 0, q'[0] == 7}; nysol0 = NDSolve[yIVP, {y}, {t, ...

4

I am not sure if this meets what you are looking for. But too small to put it in comment. Mathematica already implements zero order hold in the control system functions. Here is a quick example I wrote to show how to use it. The f(t) function has to be made a transfer function (using Laplace) and then you can use the ZOH option in the conversion. Clear[f, ...

4

You have a numerical accuracy problem more than anything else. The mesh points are not computed all that accurately, and you have to allow for it in your code. For example, Plot[Sin[x], {x, 0, N[8 Pi]}, Mesh -> {{1}}, MeshFunctions -> (Boole[Chop[Cos[#1], .005] == 0 && #2 > 0] &), MeshStyle -> {PointSize[Large], Red}] works ...

4

ss[x_, n_] := Flatten@Position[CoprimeQ[#, Sequence @@ Prime[Range@n]] & /@ Range@x, True]

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