# Tag Info

4

Please tell me if this simplified function does what you want: f[x_, n_] := Round[x, 10^(1 - n + ⌊ Log10 @ Abs @ x ⌋)] ~SetPrecision~ n Test: Table[f[x*Pi, 4], {x, {1/100, 1/10, 1, 10, 100}}] % // FullForm {0.03142, 0.3142, 3.142, 31.42, 314.2} List[0.031424., 0.31424., 3.1424., 31.424., 314.2`4.] Update The OP wrote: I understand that ...

3

The following gives what you intended: Refine[Expand[P[x, y]^2], (x|y|beta) \[Element] Reals] (* ==> Conjugate[z[y]]^2/E^((2*I)*beta*x) + 2*Conjugate[z[y]]*z[y] + E^((2*I)*beta*x)*z[y]^2 *) In cases where you can live with expansion of complex exponentials into Sin and Cos you can also use ComplexExpand[P[x, y]^2, z[y], ...

3

If you look up the term pure function you'll find that in Mathematica jargon (as e.g. used in documentation) it actually means something that in computer science jargon is typically called an "anonymous" function. In CS jargon a pure function is usually one with no inner state, no side effects and isn't depending on any external input. The right hand side of ...

2

Probably something like this would work: f := (If[AllTrue[{##}, IntegerQ] , +##]) &

2

Most users probably want to use SetPrecision, which preserves extra digits and automagically handles fractional digits of precision. However, in this case, we need to somehow override this behavior. I'll use a custom object, sigFigNumber. First I'll define how it's displayed. Format[sigFigNumber[s_, d_]] := N[s, d] So we can see that sigFigNumber has ...

2

This is a problem for anything that uses machine precision floats, e.g. Mathematica, Matlab, C, etc. Consider the simpler example $1/10$. In base 10, this fraction has the finite decimal expansion $$1/10 = 0.1$$ But your machine would store this number (and all floats) in binary. The problem is, in binary $1/10$ has the infinite decimal expansion  1/10 ...

2

Coefficient[E^(I a (t - b)) // ExpandAll, E^(I a t)] (* Exp[-I a b] *)

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