The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Tag Info

Hot answers tagged functions

11

List available as EntityList[EntityClass["WolframLanguageSymbol", "Experimental"]]

9

_ matches one thing. __ matches one or more things. ___ matches zero or more things.

8

The answer is simple: First, you really need to look up the documentation of ##. It means "take all arguments". But more importantly, you can use the property that a > b stays unevaluated when neither true or false can be computed. So check this out: If[#1 > #2, ##] &[a, b] (* If[a > b, a, b] *) Do you see how ## converts this construct into a ...

7

f[a, l[],l[]] is already concise. You may save a few key strokes using: f[x, ##] & @@ l f[x, b, c] Also f[x, ## & @@ l] f[x, b, c] and f[x, Sequence @@ l] f[x, b, c] f @@ Prepend[l, x] f[x, b, c]

6

To understand how the SlotSequence (##) works, use Trace Trace[If[#1 > #2, ##] &[22, 21]] Trace[If[#1 > #2, ##] &[21, 22]]

6

Use ComplexExpand and then Simplify: Simplify[ComplexExpand[ReIm[(-I a - m^2) Log[(I m^2)/(2 a)]]], a > 0] Simplify[ComplexExpand[ReIm[(-I a - m^2) Log[(I m^2)/(2 a)]]], a < 0] {(a π)/2 - m^2 Log[1/(2 a)] - m^2 Log[m^2], -((m^2 π)/2) - a Log[1/(2 a)] - a Log[m^2]} {-((a π)/2) - m^2 Log[-(1/(2 a))] - m^2 Log[m^2], (m^2 π)/2 - a Log[-(...

6

My first guess when I see parenthesized exponents is that this represents a derivative of a multivariate expression. To check this guess I try FullForm[%] and look at what that shows me. That confirms there is a Derivative wrapped around your HypergeometricPFQ If I use NIntegrate instead of Integrate to get an approximate result instead of an exactly ...

5

Using pts from mikado's answer: DelaunayMesh[pts]["Faces"] {{3, 4, 1}, {1, 4, 5}, {1, 2, 3}, {1, 5, 6}} Grid @ %

4

You might find the following works. I'll create some points pts = Table[(5 + t) {Cos[t], Sin[t]}, {t, 0, 5}] // N (* {{5., 0.}, {3.24181, 5.04883}, {-2.91303, 6.36508}, {-7.91994, 1.12896}, {-5.88279, -6.81122}, {2.83662, -9.58924}} *) and extract the cells of the triangulation MeshCells[DelaunayMesh[pts], 2] (* {Polygon[{3, 4, 1}], Polygon[{1, 4, 5}],...

4

a = 30; f[x_] := Sqrt[2/a] (3/5 Sin[2 \[Pi] x/a] + 4/5 Sin [(9 \[Pi] x)/a]) Plot[f[x], {x, 0, a}, AxesLabel -> {x, "f(x)"}, PlotStyle -> {Black, Dashed}] Note that you forgot the closing ) in the AxesLabel expression f(x). When you actually type the input, you may want to take advantage of the Mathematica front end by typing Esc p Esc (with the ...

4

With f[x__Integer] := ... you can use {x}[[i]] to get the ith argument.

4

eqn = ψ[x] (k x^2/2 - En) - ℏ^2 ψ''[x]/(2 m) == 0; sol = DSolve[eqn, ψ, x][] (* {ψ -> Function[{x}, C ParabolicCylinderD[(-2 En Sqrt[m] - Sqrt[k] ℏ)/( 2 Sqrt[k] ℏ), (I Sqrt k^(1/4) m^(1/4) x)/Sqrt[ℏ]] + C ParabolicCylinderD[(2 En Sqrt[m] - Sqrt[k] ℏ)/( 2 Sqrt[k] ℏ), (Sqrt k^(1/4) m^(1/4) x)/Sqrt[ℏ]]]} *) Verifying ...

3

If you want to determine a symmetric matrix $A$ such that if $x=(1,x_1,x_2,x_3,x_4)$ and $$x^T A x = 3 + x_1 - 2 x_4 + 2 x_3 x_4 + x_2 (-x_3 + x_4)$$ then the following (based on the comment by @yarchik) should do that: (* Create a symbolic symmetric matrix *) A = Table[a[Min[i, j], Max[i, j]], {i, 0, 4}, {j, 0, 4}]; (* Quadratic form *) y = 3 + x1 - 2 ...

3

Szabolcs's answer (wrapping the sequence x with List and using Part) is the way. An alternative is to use Indexed ClearAll[f2] f2[x__Integer] := Indexed[{x}, 1] + Indexed[{x}, 2] f2[1, 2, 3, 4, 5] 3 You can also use Slot (#): ClearAll[f3, f4] f3[x__Integer] := Slot + Slot &[x] f3[1, 2, 3, 4, 5] 3 f4[x__Integer] := #1 + #2 &[x] f4[...

3

The O representation of an expansion point of Infinity is obtained with: O[x, Infinity] (see this part of the documentation for O). So, you just need to do: M = { {1+5/s+6/s^3+O[s,Infinity]^4,1+8/s+4/s^2+O[s,Infinity]^4}, {1+2/s+2/s^3+O[s,Infinity]^4,1-1/s+8/s^3+O[s,Infinity]^4} }; Det[M] //TeXForm \$-\frac{6}{s}-\frac{25}{s^2}+\frac{4}{s^3}+O\...

2

Why not just use Solve? Solve[rho[r] == z && r>0, r, Reals] {{r -> ConditionalExpression[Sqrt[1 + z^2], z > 0]}} For values of q other than -1 you will also need to specify the value of z. For example: q = 1/2; Quiet @ Solve[rho[r] == 2 && r>0, r, Reals] //N {{r -> 1.45108}} You can use ConditionalExpression with ...

2

Change a+1to a++ For[m = 0, m < 0.05, m++, For[a = 5, a < 20, a++, a1 = a*(a/2);x[m] = a1]] x (*361/2*)

2

symbols = Array[Symbol["x" <> ToString@#] &, 5]; ClearAll[f]; f[## & @@ (Pattern[#, Blank[]] & /@ symbols)] := Evaluate[Sin[Times @@ symbols]]; f[a, b, c, d, e] Sin[a b c d e] f @@ {a, b, c, d, e} Sin[a b c d e]

2

As suggested, I'm expanding my comment into an answer The problem here is the HoldAll attribute of ContourPlot. Like Plot and similar functions the process goes something like this: Look at the first argument, and decide what form it has: If it's a list, the user wants to plot multiple functions If it's an equation with ==, the user wants to plot the ...

1

As with most *Q functions, CoprimeQ will evaluate to True or False immediately: CoprimeQ[a,b,c] False You could instead use GCD: FindInstance[ a + b == c && And @@ Thread[GCD @@@ Subsets[{a, b, c}, {2}] == 1], {a, b, c}, Integers ] {{a -> 1, b -> 0, c -> 1}} although this approach won't work to find your example.

1

Clear[f, lhs, rhs] {lhs, rhs} = Transpose@ToExpression[ {StringJoin["x", #, "_"], StringJoin["x", #]} & /@ Array[ToString, 4]]; Evaluate[f @@ lhs] := Evaluate[Sin[Times @@ rhs]] f[a, b, c, d] (* Sin[a b c d] *)

1

In the definition of modes, you set a new value for U here: U = (U /. Table[var2[[i]] -> nn[[i]], {i, 1, Length[var2]}]); Any subsequent calls to mode will simply return this value. Try instead modes[j_] := Module[{nn}, nn = Last[ Transpose[ Last[SingularValueDecomposition[Rarz /. \[Omega] -> s2[[j]]]]]]; U /. Thread[var2 -> nn] ] ...

1

Try ?NumericQ and assign the NSolve result to h h[r_?NumericQ, R_?NumericQ, l_?NumericQ, n_?NumericQ] :=h /. NSolve[ l^2 == r^2 + R^2 - 2 h^2 -2 Sqrt[(r^2 - h^2) (R^2 - h^2)] Cos[2 Pi/n] && h >= 0, h,Reals][] DensityPlot[h[r, 1, l, 4], {r, 0, 1}, {l, 0, 1}]

1

If HeavisideTheta = 1, is HeavisideTheta in v11.3 equal to UnitStep in v5.0? For calculus purposes, sure. Can I replace UnitStep with HeavisideTheta? HeavisideTheta[] is what you should be using in version 6 and later versions, because it's the one now supported extensively by the calculus functions. In earlier functions, you have to settle for ...

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