# Tag Info

6

In Mathematica you can use $\it{\text{expression // TeXForm}}$ to get the TeX code for any mathematical expression you have written down (also works nicely for arrays and matrices). For your problem Sum[ 1 + 2 Floor[Sqrt[r^2 - 3 x^2]], {x, -Floor[r/Sqrt[3]], Floor[r/Sqrt[3]]}] + Sum[2 Floor[ Sqrt[r^2 - 3 x^2] + 1/2], {x, -Floor[(r/Sqrt[3]) + ...

2

Simplify[(Cos[2*a + b + c]*Tan[a + 2*b + 2*c])/ Sin[(b + c - a)/2]] /. (b -> Pi - a - c) // TrigExpand Tan[a] Simplify[(Sin[(6*Pi)/5 + x])^2 + (Sin[(4*Pi)/5 - x])^2 // Simplify, Pi/5 + x == ArcCos[m^-1]] // Together (2*(-1 + m^2))/m^2

0

I agree with The Toad's comment that Sjoerd's arrow plots are the right way to show this schematically. As an engineer (apologies) I'd find it useful for Mathematica to plot delta functions schematically as Sjoerd has shown with scaled arrows. But this seems to be more about adding functionality to Plot[] rather than approximating DiracDelta[]. How might ...

7

evenFQ[f_] := Simplify[f[t] - f[-t]] === 0 oddFQ[f_] := Simplify[f[t] + f[-t]] === 0 Examples: ef[x_] := x^2 of[x_] := x^3 evenFQ/@ {ef, of} {True, False} oddFQ/@ {ef, of} {False, True} evenFQ /@ {# &, Im, Sin, Tan, Sinh, Erf} {False, False, False, False, False, False} oddFQ /@ {# &, Im, Sin, Tan, Sinh, Erf} { True, ...

5

Rather than imposing x>0 one can also do FullSimplify[ ForAll[x, myOddFunction[x] == myOddFunction[-x]]] which yields False.

4

You need Simplify with an assumption: myOddFunction[x_] := x^3; Simplify[ Equal[myOddFunction[x], myOddFunction[-x]], x > 0 ] False Refine also works in this case, again with the appropriate assumption: Refine[Equal[myOddFunction[x], myOddFunction[-x]], x > 0] False

5

As MarcoB posted before me this has to do with evaluation differences. Simply setting HoldFirst on pp produces the original plot: SetAttributes[pp, HoldFirst] pp[ψ_, options___] := ParametricPlot[{r, ψ}, {r, -1, 1}, options, PlotRange -> {Automatic, 1.05 {-1, 1}}] pp[ZernikeR[100, 0, r]] You will want this attribute anyway as without it the ...

6

This is a comment rather than an answer, but it grew too long for the comment box, and I wanted to show graphics, so I'll leave it here in hopes that someone better versed in the inner workings of MMA might explain this behavior. I am using your definition of the wrapper function pp. First of all, I get a slightly different version of the "wrong" function: ...

1

Eliminate the options and impose a reasonable WorkingPrecision: Clear[pp]; pp[\[Psi]_] := ParametricPlot[{r, \[Psi]}, {r, -1, 1}, PlotRange -> {Automatic, 1.05 {-1, 1}}, WorkingPrecision -> 200]

3

Edit: see the bottom of this post for the best solution. The documentation for CoefficientList says: The dimensions of the array returned by CoefficientList are determined by the values of the Exponent[poly, vari]. ser1 = Series[ArcTan[x]/(1 - x^2), {x, 0, 10}]; ser2 = Series[ArcTan[x]/(1 - x), {x, 0, 10}]; Exponent[ser1, x] Exponent[ser2, x] 9 ...

1

Supposing that you want a DownValues definition rather than a Function you could use: (* with your expression assigned to expr *) (x \[Function] x_) /@ Variables[expr]; f[Sequence @@ %] = expr;

0

Why not to use a list for your arguments? Something like: f1[αvars_, βvars_] := {αvars[[1]] + ..., ..., βvars[[5]] ... } Or, as I can see you have double indicies for your variables. Can you formulate your equations as matrix manipulation? This can significantly simplify the task if possible.

6

If you have a list of variables stored in vars in the desired order and expr is the function's formula, then f = Function @@ {vars, expr} will define a function for you. If you're content with the variables being in their sorted order and the expression expr is polynomial-ish (test Variables[expr] first), then f = Function @@ {Variables[expr], expr} ...

6

It was actually a lot easier than I thought f = Function @@ {vars, expr}

1

f[ω0_, α00_, α01_, α02_, α10_, α11_, α12_, α20_, α21_, α22_, β01_, β02_,β11_, β12_, β21_, β22_] := ... where ... is the list in your OP. N.B. you're missing ω1 as an argument, I assume that's intentional...

0

Hey dude I know this is a year late but I have another option that people might be interested in :) You can also use the modulus to create a periodic waveform similar to previous comments but this is the "uncompressed" version :)! f[t_] := t; periodicf[t_] := f[Mod[t, 10] - 5]; Plot[periodicf[t], {t, -100, 100}] You'll notice that I've shifted the t ...

4

f1 = Which[# < 10, ## &[#, 0], # > 10, ## &[0, #]] &; f2 = ## & @@ Which[# < 10, {#, 0}, # > 10, {0, #}] &; f3 = ## & @@ {Append, Prepend}[[1 + Boole[# > 10]]][{#}, 0] &; f4 = ## & @@ {Identity, Reverse}[[1 + Boole[# > 10]]][{#, 0}] &; f5 = Which[# < 10, {#, 0}, # > 10, {0, #}] /. List -> ...

4

Here's a way to define a function that does your computation: With[{WN = WhiteNoiseProcess[NormalDistribution[0, 10]]}, aV[m_] := Module[{data, points, yBinLst, meanLst}, data = RandomFunction[WN, {1, 10000}]; points = data["Values"]; yBinLst = Partition[points, m]; meanLst = Mean /@ yBinLst;; Total[Differences[meanLst]^2]/(2 ...

14

Introduction This post is long overdue as I have been repeatedly asked to explain code of mine containing these things. As I see increased use of this construct by others perhaps it is past due also. SparseArray objects can behave as functions accepting certain arguments to return internal data or efficiently return data in certain forms. These are known ...

4

Using the option Evaluated->True or wrapping the first argument of Plot with Evaluated gives a 100x speed-up: ls1[t_] := Quantity[10, "Nanometers"]/t Plot[ls1[Quantity[t, "Seconds"]]/Quantity[1, "SpeedOfLight"], {t, 0, 10}] // Timing ls2[t_] := Quantity[10, "Nanometers"]/t Plot[ls2[Quantity[t, "Seconds"]]/Quantity[1, "SpeedOfLight"], {t, 0, 10}, ...

4

So it seems that Nest is limited to 32-bit integers for the 3rd argument. The way around this is to apply Nest to the result of the first ~2^32 Nests. Supplying his own function using Fold, @martin suggests f[x_, r_] := Nest[# + Log[#] &, x, r]; g[r_, times_] := Fold[f[#1, #2] &, f[2., r], ConstantArray[r, times - 1]]; {f[2., 3*10^3], g[10^3, 3]} ...

1

As requested, I'm expanding on my comment above, in which I noted that $$\frac{n^{x} - n^{-x}}{n^x + n^{-x}} = \tanh [ (\ln n) x]$$ If you want to coax Mathematica to show this for you, you have to be a little tricky. In particular, Mathematica will automatically evaluate Exp[Log[n] x] into n^x unless you tell it not to. However, if you Hold the ...

2

If you wanted to do it with a function : solveme[a_] := Flatten[{a, Values[Solve[a*x - 10 == 0, x]]}] Note that the Flatten in my answer and the [[1,1]] are both ways to remove nested {}'s. Chen's does it by selecting Part mine does it by extracting the Values from Solve then using Flatten to remove nested lists. Pop in a range of values for a result = ...

3

I believe this question should eventually be closed as its elements have been addressed before. However since you are new I hope to give a better welcome than merely "go read this" etc. To that end: If you can solve your equation Symbolically you can use Solve once, then populate values of a as desired. The output format of Solve is a List of Lists of ...

5

How about Table[{a, x /. Solve[a*x - 10 == 0, x][[1, 1]]} // N, {a, 1, 10}] ? You can then export to .csv using Export["ans.csv", %].

2

Limit takes Assumptions Clear[f] f[x_] := Limit[(n^x - n^(-x))/(n^x + n^(-x)), n -> Infinity] Assuming[{#}, f[x]] & /@ {x < 0, x == 0, x > 0} {-1, 0, 1} Plot[f[x], {x, -5, 5}, Exclusions -> 0, Epilog -> {Red, AbsolutePointSize[6], Point[{0, f[0]}]}]

0

Repeated can be very helpful. Also you can use +x as a shorthand for Plus[x], and x can be bound to a sequence. _Integer is the pattern for an expression with head Integer. (For my description of heads please see Is there a summary of answers Head[] can give? and Why can't a string be formed by head String?) Therefore for (b): Cases[list, {x : ...

4

Here's a simple fix/workaround. It appears that all you need to do to make your code work as intended is to make the following change to your $dateFormat assignment:$dateFormat = {"Year", "", "Month", "", "Day", "", "Hour"} This generates an identical string to your test example, but it appears that the empty strings are necessary to correctly parse the ...

15

In addition to the error messages quoted in the question the line returns: GeneralUtilitiesBenchmarkingPackagePrivate`plot[ IndexBy[{{{16, 9.37132*10^-6}, . . . IndexBy was removed from 10.1.0: Note that IndexBy will be removed in a future version of Mathematica. It was something that was considered for 10.0.0 but didn't make the cut. – Stefan R ...

3

Just sample your function over a 2D window with a Table. f[x_,y_]:= 1-2*Sinc[2(x^2 + y^2)] step = .2; kern = Table[f[x,y], {x, -3, 3, step}, {y, -3, 3, step}]; The dimensions of the kernel can be returned with Dimensions[kern]. Experiment with values of step and window sizes. Now just do an ImageConvolve[img,kern] and optionally use ImageAdjust to ...

3

Given that you just want to relabel the square each time, it's probably easiest just to view this as a set of permutations. Imagine numbering the corners of the square clockwise from the upper left. When we do an operation on the square, we could then write down a list of the corner that's in each position. For example, {1,2,3,4} would correspond to the ...

4

You have defined the elements of group and could approach as follows: r[a_] = RotationMatrix[a Degree]; rot = {r90, r180, r270} = r /@ Range[90, 270, 90] ref = {rh, rv, d1, d2} = ReflectionMatrix[#] & /@ {{1, 0}, {0, 1}, {1, 1}, {-1, 1}}; tab = {IdentityMatrix[2]}~Join~rot~Join~ref; rules = {IdentityMatrix[2] -> "\!$$\*SubscriptBox[\(R$$, ...

0

Just to document what @Guesswhoitis. said in coments, \begin{align}x_0&=n\\x_{k+1}&=π(x_k)+n+1\end{align} which can be written CompositeA[n_Integer] := FixedPoint[n + PrimePi[#] + 1 &, n] or rr = 10^2; x[0] = 1; x[1] = rr; x[k_] := PrimePi[x[k - 1]] + x[1] + 1 x@5 On a different note, the same goal can be accomplised with CompositeB[a_, ...

7

My guess is that Tally preallocates a number of bins equal to 10% of the length of the list. If the need exceeds that, then it probably has to reallocate the bins, apparently in a time-consuming manner. Table[ l1 = l2 = RandomInteger[{1, max}, 10 max]; l2[[-1]] = -1; {First@Timing@Tally[l1], First@Timing@Tally[l2]}, {max, 2^Range[12, 21]}] // ...

8

This is more of a comment than an answer but it's too long for a comment box and I hope to extend it as I learn more. My first thought was that the negative value might be preventing some optimization so I looked for a counterexample and found something surprising: Table[ With[{a = RandomInteger[{1, 100000}, 1000000 + x]}, First @ Timing @ Do[Tally[a], ...

2

It appears to be correct: ins = n /. FindInstance[Floor[(3/2)^n] == Floor[(-1 + 3^n)/(-1 + 2^n)] , n, Integers, 20 ] {4811, 1040, 4155, 469, 4050, 733, 4039, 1415, 2799, 2403, 2571, 4168, 252, 207, 4804, 2239, 4660, 535, 1603, 4756} (Mod[((3^# - 1)/(2^# - 1)), 1] - Mod[(3/2)^#, 1] == (3^# - 1)/(2^# - 1) - (3/2)^#) & /@ ...

0

Would this help? ToString[FromCharacterCode[92]] <> "\sum_{n = 1}^{4} 0.9^{n - 1} (1 - 0.9)" (* \\sum_{n = 1}^{4} 0.9^{n - 1} (1 - 0.9) *)

4

Yet another approach; However you do not have to worry about truncating the signal, just scale it. Plot[WaveletPsi[HaarWavelet[], x/4], {x, 0, 10}, Exclusions -> None, PlotRange -> {{0, 10}, {-2, 2}}, AxesOrigin -> {0, -1.5}]

3

You can also use Boole to truncate SquareWave: Plot[SquareWave[x/4] Boole[0 <= x <= 4], {x, 0, 10}, Exclusions -> None, BaseStyle -> Thick, Frame -> True, Axes -> False, PlotRangePadding -> {0, 1}] Using Piecewise[{{SquareWave[x/4], 0 <= x <= 4}}] instead of SquareWave[x/4] Boole[0 <= x <= 4] gives the same result.

4

tsw[n_?NumericQ] := Piecewise[{{1, n <= 2}, {-1, 2 <= n <= 4}}] Plot[tsw[n], {n, 0, 10}, Exclusions -> None]

2

As to the second question: you could change ConditionalExpression itself. Unprotect[ConditionalExpression] ConditionalExpression[a_, ___] := a but this is potentially dangerous. Who knows where else ConditionalExpression is being used? So, a safer alternative is just change the way it's being output Unprotect[ConditionalExpression] ...

1

Alternatively, and perhaps more generally, conditions can be eliminated by prepending First, as in First@Integrate[1/(x^2 + y^2), {y, -Infinity, Infinity}]

1

Use Normal with Series f[x_] = Series[1/Sqrt[x], {x, 1, 2}] // Normal 1 + (1 - x)/2 + (3/8)*(-1 + x)^2 Use GenerateConditions -> False with Integrate Integrate[1/(x^2 + y^2), {y, -Infinity, Infinity}, GenerateConditions -> False] Pi*Sqrt[1/x^2]

2

Mathematica does not like your h[i]s. If you introduce shrt[head_, indices_] := ToExpression[StringJoin[ ToString /@ Flatten[ {head, indices}]]] so that e.g. shrt[h,1] becomes h1 or shrt[h,{i,j}] hij Then this works: S = 10^-9.2; cl = 3*10^8 ; f = 5.9*10^9; w = cl/f ; A = (4*π/w)^(2/1); β = 2.5 ; m ...

0

ranpolyplot[n_, r_] := Module[{x}, ListPlot[{Re@#, Im@#} & /@ (x /. NSolve[FromDigits[RandomReal[r, n + 1], x]]), AspectRatio -> 1]] ranpolyplot[100, {1, 2}]

0

expr = 1/4 (-(1/4) + Sqrt[5]/4 + I Sqrt[5/8 + Sqrt[5]/8]) (-1 - Sqrt[5] + 2 Sqrt[7/2 + (5 Sqrt[5])/2]); expr2 = expr // Simplify You can in this case -- and may with the full expressions -- get a simpler form if you express in terms of the GoldenRatio (expr3 = (expr /. Sqrt[5] -> 2 Inactive[GoldenRatio] - 1) // Simplify // Activate) // ...

1

ranpolyplot[a_, n_] := Module[{roots, RI, f, x}, f[x_] = Sum[a[[i]] x^(i - 1), {i, n}]; roots = x /. NSolve[f[x] == 0, x]; RI = Transpose[roots /. z_ -> {Re[z], Im[z]}]; ListPlot[RI, PlotRange -> {{-1.5, 1.5}, {-1.5, 1.5}}, AspectRatio -> 1, AxesLabel -> {Re, Im}]]] Now you have to feed it the coefficients and order of polynomial. coeff = ...

2

Root-expressions are very useful. It is worth reading the documentation about it. Often, doing computations with Root-expressions is simpler and more general than with Radicals. Having said that, it might be that you are looking for something like this: FullSimplify[1/4 (-(1/4)+Sqrt[5]/4+I Sqrt[5/8+Sqrt[5]/8]) (-1-Sqrt[5]+2 Sqrt[7/2+(5 Sqrt[5])/2]), ...

3

Cases[list, x : {_, _} :> Plus @@ x] (* {3, 9, 6, e + f, Cos[b] + Sin[a]} *) Cases[list, x : {_Integer, _Integer} :> Plus @@ x] (* {3, 9, 6} *) Cases[list, x : {_, __} :> Plus @@ x] (* {3, 8, 9, 6, a + b + c, e + f, Cos[b] + Sin[a]}*) Cases[list, x : {___} :> Plus @@ x] (* {3, 2, 8, 9, 6, a + b + c, e + f, g, 0, Cos[b] + Sin[a]} *) Or ...

Top 50 recent answers are included