Tag Info

Hot answers tagged

10

You can input numbers in any base up to 36 using the notation base^^digits. Digits over 9 are represented using a, b, c, ... You can print numbers in any base up to 36 using BaseForm. Thus, In[1]:= a=2^^0.10101 Out[1]= 0.65625 In[2]:= BaseForm[a^2,2] Out[2]//BaseForm= Subscript[0.0110111001, 2] Note that the internal representation of numbers doesn't ...


6

I feel like I should be prefacing this answer with three confessions, considering that this is an arithmetic question. First, I had a hard time with the multiplication tables until I was nine years old. Second, even after I finally got the hang of multiplication, I was never a fan of multiplying from right-to-left; I preferred going left-to-right. (Arthur ...


6

You can enter a number in an arbitrary base using base^^digits: alpha = 2^^0.10101; BaseForm[alpha, 2] BaseForm[alpha^2, 2]


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.03142`4., 0.3142`4., 3.142`4., 31.42`4., 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] *)


1

You have quite a small data set, so a really inefficient brute force search will still run pretty fast (<1 sec on my computer). I stress that this is STUPID way to do it, and with list manipulation you can surely make it MUCH more efficient. But as I said - it works. First, transform the data so that you could retrieve the data by calling f[x1,x2,x3], ...



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