# Tag Info

3

Since gh is a tensor, you need to say what rank it is, so replace {gh, _Real} with {gh, _Real, 2} to fix the error. costFxn = Compile[ {{P, _Real}, {Ns, _Integer}, {gh, _Real, 2}, {Kg, _Integer}, {G, _Integer}, {betaGN, _Integer}}, Sum[ -Exp[Kg/(P gh[[g, n]])] (Kg * betaGN)/ Log[2] ...

8

The general equation of ellipse (here) is given by: ellipse[x_, y_] = a x^2 + b x y + c y^2 + d x + e y + f == 0; solving using 5 pintos result in: SeedRandom[3]; pts = RandomReal[{-1, 1}, {5, 2}]; sol = Solve[ellipse @@@ pts]; ellipse[x, y] /. sol[[1]] // Simplify (*a (-0.275185 + 1. x^2 + x (0.189022 + 0.566953 y) + 0.1281 y + 0.397124 y^2) == ...

3

This could also be a case where the version-10 command Inactive may be useful. Before inserting an inactive version of Exp, I also split up exponents consisting of sums by temporarily replacing powers of E with a function exp that only implements the desired multiplicative property. To cast these replacements in the form of a function expExpand, we have to ...

21

The following is based on the fact that the determinant of a matrix is equal to zero when two rows are the same. Thus, if you plug any of the points in, you get a true statement. SeedRandom[3]; pts = RandomReal[{-1, 1}, {5, 2}]; row[{x_, y_}] := {1, x, y, x*y, x^2, y^2}; eq = Det[Prepend[row /@ pts, row[{x, y}]]] == 0 (* Out: ...

0

Times is converted internally to power because Times is not a canonical form. I would also suggest the following: r=Dot @@ Exp /@ Level[(Exp[5 (a + b + c)] // ExpandAll), {2}] (*E^(5 a).E^(5 b).E^(5 c)*) if you want to bring back the result,then: Times @@ r (*E^(5 a + 5 b + 5 c)*)

4

The desired representation will automatically simplify when evaluated Exp[5 a]*Exp[5 b] To get and maintain the desired factored form requires any of several methods of holding the evaluation. As suggested by DumpsterDoofus, one approach is to use an unassigned operator. A slightly modified version of this approach: expr = Exp[5 (a + b)]; f = ...

3

If you want to change the original list "directly" (inplace) you can do it with HoldFirst: SetAttributes[Exchange, HoldFirst]; Exchange[list_, a_, b_] := list[[{a, b}]] = list[[{b, a}]] list1 = {1, 2, 3, 4}; Exchange[list1, 3, 1]; list1 {3, 1, 2, 4} Multiple swaps: list1 = {1, 2, 3, 4}; Exchange[list1, ##] & @@@ {{4, 1}, {2, 3}} // Flatten; ...

8

The problem here is that in Mathematica, parameters of a function are not local variables. So trying to modify a parameter of a function inside it's body will lead to an error. The reason is that function arguments are evaluated, when the function is called so that it is actually the result of this evaluation that's textually substituted for the function ...

5

This works: RootReduce@JordanDecomposition[{{2, -5, 8, 12}, {1, -2, 4, -8}, {0, 0, 2, -5}, {0, 0, 1, -2}}] (* { {{2-I,4/3,2+I,4/3},{1,0,1,0},{0,-1/12-I/6,0,-1/12+I/6},{0,-I/12,0,I/12}}, {{-I,1,0,0},{0,-I,0,0},{0,0,I,1},{0,0,0,I}} } *)

2

If you want compare form of plot better to use CorrelationDistance v1={555697, 557508, 562226, 561616, 556815, 551125, 551144} v2={666278, 667190, 668101, 669440, 661562, 659761, 660728} CorrelationDistance[v1, v2]/2 // N (*max value of distance - 2*) PS: read about DTW algorithm

4

A good comprehensive answer should explain why InverseFunction "didn't work", however there's been no explanation so far. A unique inverse function can be found in a region if there its jacobian is nondegenerate, i.e. its determinant doesn't vanish (Inverse function theorem) . For one - variable function it means that the derivative doesn't vanish. ...

0

You might also be interesting in looking at web-Mathematica (version 5) solution below. http://mokslasplius.itpa.lt/eksperimentai/ta-kinio-kruvio-judejimas-nevienalyciame-lauke#etn09

8

The integrals can in fact be done exactly, but only if you make some use of the symmetries of the problem first. The circular ring geometry implies that the magnetic field will look the same in any vertical plane going through the rotation axis (which we call the z axis). Therefore, we don't need to specify three independent variables x, y and z to do the ...

1

purify[f_, x_] := Function @@ {f /. x -> #} fun = 30*x^2 (1 - x)^2; inv = InverseFunction[purify[fun, x]][x] // Quiet LogPlot[{fun, inv}, {x, 0, 1}, PlotTheme -> "Detailed"]

10

Solve also works Solve[y == 30 x^2 (1 - x)^2 && 0 < x < 1, x, Reals] {{x -> ConditionalExpression[Root[-y + 30 #1^2 - 60 #1^3 + 30 #1^4 &, 2], 0 < y < 15/8]}, {x -> ConditionalExpression[Root[-y + 30 #1^2 - 60 #1^3 + 30 #1^4 &, 3], 0 < y < 15/8]}} Use ToRadicals to get it in a nice looking form.

6

Reduce appears to provide useful information: Reduce[{(30*x^2 (1 - x)^2) == y, 0 < x < 1}, x, Reals] (0 < y < 15/8 && (x == Root[-y + 30 #1^2 - 60 #1^3 + 30 #1^4 &, 2] || x == Root[-y + 30 #1^2 - 60 #1^3 + 30 #1^4 &, 3])) || (y == 15/8 && x == 1/2) ToRadicals can be used to put this into a more familiar form. ...

6

Your second approach is nearly correct. Modify it like so. f = 30*#^2 (1 - #)^2 &; g = InverseFunction[f] 1/30 (15 - Sqrt[15] Sqrt[15 - 2 Sqrt[30] Sqrt[#1]]) & Plot[f[g[x]], {x, 0, 1}]

4

The fact that False is on his own web page indicates against this being a change between versions but rather something he failed to notice. Following his equivalence we also have the last kernel element (a4) in the last place in the third row of the left matrix, an indeed that matches the actual output: m = NestList[RotateRight, {a1, a2, a3, a4, 0, 0}, 2] ...

3

You forgot to put the body of the function in a Module. You also have A where I assume you mean to have a. Corrected: f[n_] := Module[{a, b, v}, a = Table[i^j, {i, 1, n}, {j, 1, n}]; b = Inverse[a]; v = Table[Mod[i, 2], {i, 1, n}]; b.v ] f[5] {128/15, -(40/3), 22/3, -(5/3), 2/15} However, for this particular function I would ...

0

Solution (This solution worked for my particular case.) Install Mathematica 9 alongside with Mathematica 10 then reinstall Mathematica 10 I have no idea why it worked. I do not have enough time now to find out. I will appreciate any comments for a further research of an answer... If you use Arch Linux install tree with: $sudo pacman -S tree The purpose ... 2 I think it is a working precision problem because you work with big numbers (for Factorial, Gamma and HypergeometricU these numbers are big). Therefore, you can simply increase the precision Nprob[α_, γ_, T_, k_] := prob @@ SetPrecision[{α, γ, T, k}, 100] prob[0.145, 1.71, 53, 100] Nprob[0.145, 1.71, 53, 100] 0. ... 7 Here is the example from the documentation adapted for the OP's data: data = MapIndexed[ Flatten[{#2, #1}] &, {2, 5, 9, 15, 22, 33, 50, 70, 100, 145, 200, 280, 375, 495, 635, 800, 1000, 1300, 1600, 2000, 2450, 3050, 3750, 4600, 5650, 6950}]; f = Interpolation@data (* InterpolatingFunction[{{1, 26}}, <>] *) pwf = Piecewise[ ... 8 There is no documented built-in way to convert the InterpolatingFunction object into explicit Piecewise form (thanks to @MichaelE2 for the link!). So the only possibility to get an explicit interpolating function is to re-implement the built-int Interpolation in the high-level Mathematica language. I have already done this for the built-in "Spline" method ... 3 function = c1 # + c2 #^2 + cn #^3 & ; constraints = {function[1] == 5, function'[-1] == 3, function''[1] == 1}; Solve[constraints] (* {{c1 -> 97/22, c2 -> 7/11, cn -> -(1/22)}} *) -3 f[x_, n_] := (1/2 + ArcTan[n x]/Pi)^n; Limit[f[x, n], n -> Infinity, Assumptions -> x > 0] E^(-(1/(Pi x))) 6 As Öskå commented Show and Graphics is the way to go: m = {{0, 1}, {-1, -3}}; ev = Eigenvectors[m]; Show[ StreamPlot[m.{x, y}, {x, -3, 3}, {y, -3, 3}], Graphics[{Red, Arrow[{{0, 0}, #}] & /@ ev}] ] 1 I think this readily explained by looking at the own-values of the variable after the assignment is made. v = {a, b, c}; v[[2]] = Sequence[e, f]; OwnValues @ v {HoldPattern[v] :> {a, Sequence[e, f], c}} It's rather like Defer, so it will behave like {a, e, f, c} under standard evaluation. But it can behave differently in non-standard evaluation. ... 3 This is a manifestation of the issue raised in this question, that Equal for packed arrays is handled in a non-standard way, causing the Listable attribute to be ignored. Range[8] returns a packed array, so for that case the non-standard evaluation kicks in. But the explicitly entered list {1, 2, 3, 4, 5, 6, 7, 8} is not a packed array, so you get the ... 1 It might be interesting for you to compare @Jens' answer with FunctionDomain (new in V10): compare[fun_] := { fun[x], FunctionDomain[fun[x], x, Reals], FunctionDomain[fun[x], x, Complexes], analyticityCondition[fun, x], singularCondition[fun, x]} TableForm[ compare /@ {Sin, Tan, f, g, h}, TableHeadings -> {None, {"Function", "RealDomain", ... 1 If you want to stick with Complement[] l = {a, y, c, d, e};; l[[Sort[Complement[l, {a, c}, {d}] /. Thread[l -> Range@Length@l]]]] (*{y, e}*) or SortBy[Complement[l, {a, c}, {d}], Position[l, #] &] (*{y, e}*) 1 It uses sorting internally (as documented, actually). For unsorted, could do as below. unsortedComplement[l1_, l2_] := Reap[Module[ {remove}, Map[(remove[#] = True) &, l2]; Map[If[TrueQ[remove[#]], Null, Sow[#]] &, l1]; Clear[remove]; ]][[2, 1]] unsortedComplement[{1, 3, 2, 8, 5}, {3, 6}] (* Out[78]= {1, 2, 8, 5} *) Extending ... 1 This should get you the desired result: Select[{a, y, c, d, e}, MemberQ[Union[{a, c}, {d}], #] == False &] {y, e} 5 I don't think there's a general function built in that can deal with all possible cases. But Reduce is quite powerful. Here is a function that seems to work for the last two examples given: singularCondition[func_, variable_] := Reduce[1/func[variable] == 0 || 1/func'[variable] == 0, variable, Reals] singularCondition[h, x] (* ==> x == -b *) ... 2 Try with Export["data_output1.txt", AA, "CSV"] 4 S = First /@ Partition[CharacterRange["a", "z"], 3, 3, 1] (* {"a", "d", "g", "j", "m", "p", "s", "v", "y"} *) It's minimal because: 3*Length@S (* 27 *) and any$S$with less cardinality will have at most$3*8= 24$characters in it's union, so it won't cover the full letter set. 2 x = Partition[letters, 3, 1, {1, 1}]; x[[1]] {"a", "b", "c"} x[[26]] {"z", "a", "b"} Generalization: fun[letter_String, n_Integer] := With[{cr = CharacterRange["a", "z"]}, Partition[cr, n, 1, {1, 1}] [[ToCharacterCode[letter] - 96]] // Flatten] fun["y", 4] {"y", "z", "a", "b"} 5 The basic reason is that once you convert a tensor expression into a SparseArray, you've "given control" of all levels of that expression to SparseArray to manage on your behalf in an efficient way (the number of levels is the rank of the tensor, to mix jargon). SparseArray will then try to maintain the illusion that those levels are still really there. ... 3 Let's define a polynomial p of one variable x depending on two parameters A and L: p[x_, A_, L_] := 96 x^8 − 192 L x^7 + (768 π^2 A^2 + 128 L^2) x^6 + (−64 L^3 − 640 A^2 π^2 L) x^5 + (2655 π^4 A^4 − 640 L^2 π^2 A^2 + 32 L^4) x^4 + (384 A^2 L^3 π^2 − 578 A^4 L π^4) x^3 + (4476 π^6 A^6 − 2760 L^2 π^4 A^4 + 128 L^4 π^2 A^2) x^2 + (456 ... 8 I've fiddled with this on and off for a while now, hesitating to decide whether it was worth posting since another answer has already been accepted. The undocumented function, ExperimentalOptimizeExpression, can be used to break down the solutions algebraically into common subexpressions, and it seemed like an approach worth sharing. On the other hand, ... 1 I don't have V10 yet, so I am just going to extend @Sektor. Let say you have a function with some divergences. I choose here a simple example like f[x_] = Product[1/(x - a[i]), {i, 3}] You can get the poles by Solve[1/f[x] == 0, x] It works if you have two variables as well like f[x_, y_] = Product[1/(x + y - a[i]), {i, 3}] Solve[1/f[x, y] == 0, x] ... 5 Version 10 has the built-in FunctionDomain f[x_]:=1/(x-3); FunctionDomain[f[x], x, Reals] (* x<3||x>3 *) Not[%]//FullSimplify (* x == 3 *) or, more directly, Not[FunctionDomain[f[x], x,Reals]]//FullSimplify (* x == 3 *) To get 3 use Not[FunctionDomain[f[x], x,Reals]]//FullSimplify //Last (* 3 *) For version 9, Not[Reduce[Abs@f[x] < ... 1 data = Import["txt file path name", "Table"] // Rationalize[#, 0] &; utt = data[[All, 1]]; ra = data[[All, 2]]; akuu = data[[All, 3]]; maxEigenn = data[[All, 4]]; rk = data[[All, 5]]; Muu = data[[All, 6]]; zz = data[[All, 7]]; mm = data[[All, 8]]; You did not specify an index for mm, I have assumed that it is i (adjust to taste). Part uses double ... 2 Rather than a guess I could provide a reasonable explanation (when lacking it usually leads astray) thus we are prompting another way offering also understanding. Since the given equation is a functional one and Mathematica does not offer a direct functionality we have to deduce with the system an adequate scheme for solving such equations. Let's ... 5 As suggested by george2079 the equation can be solved by substition: Reverse@Simplify[f[x] == 2 x + 1/x - f[1/x]/2 /. f[1/x] -> 2/x + x - f[x]/2] f[x] == 2 x To find$f^{-1}(4)\$ you can use f = 2 # &; InverseFunction[f][4] 2

18

Diagnosis Spelunking the definition of Commonest, which is written in top-level Mathematica code, I see that the two parameter form is handled by this internal function: Commonest; (* preload *) ? StatisticsDescriptiveDump`oCommonestSetLength oCommonestSetLength[list_, n_] := Catch[Block[{res, reslen, ord}, res = Tally[list]; reslen = Length[res]; ...

3

I think your operation is being obfuscated by your thinking of and describing it in reverse, and by the 0 in the outermost head. "Forward" nest Nest repeatedly adds a given head to the outside of an expression; it does not replace the inside of the expression with (some portion of) itself. This may sound like two ways to express the same thing but the ...

2

Almost the same wuyingdgg's answer but works for general parameters. g[fx[a_, b_, c_]] := fx[a, b, c] /. {a -> fx[a, b, dt], b -> fy[a, b, dt]} With[{n = 2}, Nest[g, fx[A, B, 0], n]] fx[fx[fx[A, B, dt], fy[A, B, dt], dt], fy[fx[A, B, dt], fy[A, B, dt], dt], 0] Should it be desired to have control over dt as well, then g[fx[a_, b_, dt_]] := ...

4

You can definite a function by Replace, like this f[x_] := Replace[x, {A -> fx[A, B, dt], B -> fy[A, B, dt]}, -1] And then it is easy to do that by Nest or NestList

Top 50 recent answers are included