Tag Info

Hot answers tagged

5

Given expression = (20*t^2*Erf[b + t])/(E^t^2*Sqrt[a + t^2]) can be achieved via replacement of the Head List @@ expression To find constant factors: GatherBy[List @@ expression, NumberQ] It is so because Times here is single Head for all first-level factors: TreeForm[expression] This also can prove to be useful: FactorList[expression] ...


4

I usually do something like expr = (x + 3)/4 + Exp[x] + 1 + (c + x); xCoeff = Coefficient[expr, x]; expCoeff = Coefficient[expr, Exp[x]]; rest = Collect[expr - xCoeff*x - expCoeff*Exp[x], x]; {xCoeff, expCoeff, rest} {5/4, 1, 7/4 + c}


3

You can use CoefficientList: exp = (x + 3)/4 + Exp[x] + 1 + (c + x); CoefficientList[exp, {x, Exp[x]}] (* {{7/4 + c, 1}, {5/4, 0}} *) Whether that is a convenient way depends on what you want to do with it. Following extracts the parts: {{const, ExpC}, {xC, xExpC}} = %


3

I believe Block will work for you here: mem : averageFreeEnergyDensityCompiled["square", n_] := mem = Block[{Part}, Compile[{{j, _Real}, {d, _Real}, {a, _Real}, {h, _Real}, {dx, _Real}, {th, _Real, 2}, {ph, _Real, 2}}, Evaluate[(*apply boundary conditions*) s[i1_, i2_] := Which[i1 == n + 1 && i2 == n + 1, s[1, 1], i1 == ...


1

An interesting problem which at first sight looks innocent. But then ... My (bold) conjecture is that the maximum number lg of terms you can get of this recurrence if a[1] == 1 is lg = 11. First we solve the recurrence explicitly sol = RSolve[a[n + 1] == 7 a[n] + n && a[1] == 1, a[n], n]; a[n] /. First[sol] (* Out[317]= 1/252 (-7 + 43 7^n - 42 ...


1

This is mostly a copy and paste of the brilliant answer by @WReach regarding implementation of lazy lists in Mathematica. I'll refer you to that answer for a detailed explanation of his concept of a stream and only detail the modifications I made for this particular problem. ClearAll[stream] SetAttributes[stream, {HoldAll, Protected}] sEmptyError[] := ...


1

Here's the answer to your question, how Mathematica can give you a function wich calculates the sum for all combination of the parameters n, m, and z. And you almost have found it! Simply define the function a[n_, m_, z_] := Sum[(j + n - 2)!^2/((j + n - m - 1)!*(j - 1)!), {j, 1, z - n}] Now you can calculate the correct result of your example a[7, 4, ...


1

Calculations about equality There are different kinds of "equality" used in computer programming. In Mathematica, ==, or Equal is used to assert equality. 1==1 is a True statement, and 1==2 is False. f == a/b is a statement about the relationship between f, a and b. You shouldn't use := to assert equality between f and a/b or c/d. Rather, make the ...


1

Not sure if I've understand you. Something like this?: With[{a = a[c], b = b[d]}, D[f[a, b], c]] With[{a = a[c], b = b[d]}, Solve[f == f[a, b], c]] 1/d {{c -> d f}}



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