Tag Info

New answers tagged

2

You can use $Post: $Post = If[ArrayQ@#, MatrixForm@#, #] &;


0

mestLevo[x_] := Last[RealDigits[N[x]]]; SigMest[x_, n_] := If[n == 0, Round[x] // N, Round[x 10^-mestLevo[x] 10^n] 10^-n 10^mestLevo[x]] // N;


2

Another way, which also involves a levelspec, is to use a pattern replacement rule: lis = {{a, b}, {c, d}}; Replace[lis, {x_, y_} :> {{x}, y}, {1}] (* {{{a}, b}, {{c}, d}} *) The original question asked about efficiency. Here's a comparison: pairs = RandomReal[{-1, 1}, {100000, 2}]; Replace[pairs, {x_, y_} :> {{x}, y}, {1}] // Timing // First (* ...


3

Direct solution This should be pretty fast: wrapList[lst_List]:= Module[{copy=lst}, copy[[All,1]]=Transpose[{copy[[All,1]]}]; copy ]; for example: wrapList[{{a, b}, {c, d}}] (* {{{a}, b}, {{c}, d}} *) This does a million pair list in 0.4 sec on my machine: tst = RandomInteger[100, {1000000, 2}]; wrapList[tst] // Length // ...


3

One method... Apply[{{#1},#2}&, {{a,b},{c,d}}, {1}] Apply applies a function which in this case takes two arguments and return a list of the first argument as a list and the second un-altered. The trailing {1} is a levelspec to make Apply work at the right level. All in the docs (See Apply and Map, they are your friends).


1

Personally, I would use common regural expression syntax, since this can be checked also by non-Mathematica programmers: str = "174,861.00 ( 4,053.52) 206,850.48 118.29 ( 31,989.48)"; StringReplace[str, { "," -> "", RegularExpression[" \\( +"] -> ",(", RegularExpression["\\) +"] -> ")," , RegularExpression[" +"] ...


3

This is the best I can come up quickly. It can be used much in the same way that MatrixForm is. SetAttributes[factorizationForm, HoldFirst]; factorizationForm[expr_] := If[Head[Unevaluated[expr]] === FactorInteger, CenterDot @@ Superscript @@@ expr, expr] Then FactorInteger[5!] // factorizationForm but {{2, 3}, {3, 1}, {5, 1}} // ...


3

Possibly this is sufficient: in = "174,861.00 ( 4,053.52) 206,850.48 118.29 ( 31,989.48)"; StringReplace[in, {"," -> "", "(" ~~ Whitespace -> "(", Whitespace -> ","}] "174861.00,(4053.52),206850.48,118.29,(31989.48)"


3

But if you always want to replace the sequence brace, spaces, digit, why don't you just say so? str="174,861.00 ( 4,053.52) 206,850.48 118.29 ( 31,989.48)"; StringReplace[ StringReplace[str, d1 : DigitCharacter ~~ "," ~~ d2 : DigitCharacter :> d1 ~~ d2], {"(" ~~ Whitespace .. ~~ i : DigitCharacter -> "(" ~~ i, Longest[Whitespace ...


3

There's a built-in to do just this, e.g.: IntegerString[125, 2] IntegerString[125, 16] (* 1111101 7d *


3

The default rule for spanning characters is to span symmetrically above and below the central axis of the whole expression, so in your example 2 is put at the center. To shrink the parentheses asymmetrically, option SpanSymmetric needs to be set to False: Style[ DisplayForm@RowBox[{"(", SubsuperscriptBox[2, 6, 7], ")"}], 18, Bold, ...


0

I think what you are looking for is a function that, for example takes the number fifteen and the base two, writes 15 in base 2 (which is 1111) and then returns the value one thousand, eleventy one (base 10). If that's what you're aiming at, then what you are looking for is f[number_, base_] := FromDigits[IntegerDigits[number, base]] where base says what ...


0

StringJoin @@ ToString /@ IntegerDigits[105, 3] "10220" FromDigits[ToExpression@Characters[%], 3] 105


2

One way of doing this would be using Defer or HoldForm. For example, let us define the functions a and b as follows: a[t_] := Defer[Integrate[t, {x, -∞, ∞}]] b[t_] := Defer[Integrate[t^2, {x, -∞, ∞}]] and a1[t_] := HoldForm[Integrate[Exp[-t], {x, 0, ∞}]] b1[t_] := HoldForm[Integrate[Exp[-t^2], {x, 0, ∞}]] They both return unevaluated function. ...


1

I am not certain about what you are asking, so this may be off target. My understanding is your Garch function returns a list like this one; test = {{a, 91, 48, 30, 50}, {b, 49, 81, 18, 74}, {c, 30, 23, 98, 96}}; If that is right, then defining a function garchForm[g_List] := TableForm[g[[All, 2 ;; -1]], TableHeadings -> {ToString /@ g[[All, 1]], ...


2

This is a quick possibility: myExpand[expr_] := Module[{tmp}, Unprotect[Plus]; ClearAttributes[Plus, Orderless]; tmp = HoldForm @@ {Expand[expr] /. a_Plus :> Reverse[a]}; SetAttributes[Plus, Orderless]; tmp]; w = f[r, Θ]; lapla12 = -(r/(2 μ)) (1/r D[w/r r, {r, 2}] - 1/r^2 (D[w/r, {Θ, 2}] + Cot[Θ] D[w/r, {Θ, 1}])) // myExpand


11

Declaration: This method for Windows is based on the .NET code from Todd Gayley's this wonderful answer. My .NET knowledge is absolutely ZERO, all credit goes to Todd. Code: The main idea is to extract the "Input"-style code string, convert it to the UTF-16 little endian form, which is the standard byte order in Windows, feed the bytes to system clipboard ...


2

f[subexpr_, var_] := Sort@Which[ NumberQ[subexpr], {subexpr, {var, 0}}, Head[subexpr] === Power && subexpr[[1]] == var, {1, List @@ subexpr}, MemberQ[subexpr, var], List @@ subexpr /. var -> {var, 1}, True, List @@ # /. Power[var, r_] :> List[var, r] &@subexpr ] f2[expr_, var_] := Plus @@ (#1 Superscript[var, #2[[2]]] & @@@ ...


3

Numerical approach according to Jens' comment : pde = D[u[x, t], t] - 0.2 D[u[x, t], {x, 2}] == 0; g[x_] := 1/(1 + x^2)^0.25; sol = NDSolve[{pde, u[x, 0] == g[x], u[-10, t] == u[10, t] == g[10]}, u[x, t], {x, -10, 10}, {t, 0, 20}] Plot3D[u[x, t] /. sol, {x, -10, 10}, {t, 0, 20}, AxesLabel -> {Style["x", Italic, Red, 20], ...



Top 50 recent answers are included