Tag Info

Hot answers tagged

12

While it would've been nice if the package handled it automatically, it can be fixed with a simple overloading of Quantity: Unprotect@Quantity; Quantity /: (0 | 0.) Quantity[_, unit_] := Quantity[0, unit] Protect@Quantity; You can add this to your init.m, so that you don't have to define it each time. You can test your examples with this: 0. Quantity[1, ...


10

Here's one idea. Hold the expression unevaluated and go up the expression tree from (near) the bottom, level by level, and evaluate. expr = HoldForm[1/((a + 2 b)/c^2)] /. {a -> 1, b -> 2, c -> 3} out = ToExpression@ToString[FullForm@#] & /@ (ReplacePart[expr, # -> Extract[expr, #] & /@ #] & /@ ...


7

Calculating eigenvalues involves solving for the roots of the characteristic polynomial, which is of degree equal to the order of the size of the matrix. When you input real numbers, it can search for the roots of the polynomial using numerical techniques. When you input exact integers (or rationals, probably) it tries to find exact answers for the roots of ...


5

Not a full answer since I need to sleep :) but more of an observation, which might help. It seems to have to do with the fact that 0 and 0. are not the same in Mathematica. This simple example shows it UnitConvert[0. + Quantity[5, "Meters"], "Inches"] (*--> UnitConvert[0. + Quantity[5, "Meters"], "Inches"] *) while UnitConvert[0 + ...


5

Try this : s[n_] := Total[ Range[n]^2] to check how it works, e.g. : s[5] // Trace There is also a purely symbolic approach, e.g. : $\quad n^2$ ~ Sum ~$n\quad$ (see Infix notation) : (n^2) ~ Sum ~ n 1/6 (-1 + n) n (-1 + 2 n) Note : Sum[ n^2, n] returns the same as Sum[ i^2, {i, n-1}] does, i.e. indefinite sums starts at 0 while ...


4

Independently I arrived at something similar to Michael's answer, yet different. I borrowed his formatting function after seeing it as it works better than what I had. Perhaps this will also be of use: evalFromBottom[expr_, lv_: 1] := If[lv > Depth@expr, expr, With[{ev = Replace[expr, x_ :> RuleCondition[x], {-lv}]}, If[expr === ev, ...


4

An oddball one using a recursive, memoizing function for the square. Clear[sq]; sq[n_Integer] := sq[n] = sq[n - 1] + n + (n - 1) sq[1] = 1; Sum[sq[n], {n, 6}] 91 It's not something I would directly use for such a goal, but you asked for something without explicit multiplications and you got it. Alternatively, if we don't interpret Dot as some ...


2

With the suggested edits from Rojo in the comments above, the following is what answers my question: plus[args__] := Row[Riffle[{args}, " + "]] Then, Block[{Plus = plus}, x + 1 + i + 4 + z] // TraditionalForm returns:


2

If exponentiation is allowed, how about this? w = 10; E^(Log[1/6] + Log[w] + Log[1 + w] + Log[1 + w + w]) 385 Explanation ClearAll[w] Sum[i^2, {i, 1, w}] 1/6 w (1 + w) (1 + 2 w)



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