Tag Info

Hot answers tagged

8

The intuitive way to understand ListCorrelate is that the kernel is "moved" to every position in the array, and the sum of the products between the kernel values and the array values at that position is stored in the output array: (if the kernel is separable, i.e. if there are two 1d kernels so that Transpose[{k1}] . {k2} == k2d, then ListCorrelate can be ...


8

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

If you wish to compute the correct values using the method you have chosen you could specify Method -> "Procedural" for Sum: CumDigitSum[x_, b_] := Sum[DigitSum[n, b], {n, 1, x}, Method -> "Procedural"] CumDigitSum[1000001, 10] 27000003 However, the problem comes form the fact that Sum attempts to speed the calculation by finding a symbolic ...


6

I think you need to use a group-theoretical construction. In this way you will have full freedom in specifying any group of permutations you need. In your case the group is G = PermutationGroup[{Cycles[{{1, 2}, {4, 5}}], Cycles[{{1, 2, 3}, {4, 5, 6}}]}]; This generates a symmetric group on {1, 2, 3}, which also forces the same permutations on {4, 5, 6}. ...


6

If you have Version 10 use the function Where in the GeneralUtilities package like this: Needs["GeneralUtilities`"] f[l_] := Where[a = Length[l], b = First[l], c = b/a, c*10] Then: f[{2, 3, 4, 5}] 5


6

I think your problem is probably related to the way OptionValue[name] is evaluated. When you use a regular List instead of an Association, you'll find the whole thing works. I don't have the mathematica-fu to understand why in detail, but here is an alternative solution that makes your function definitions pretty concise. Define a utility function that ...


5

I believe this results from Association being atomic (or "not NormalQ" as Taliesin puts it) without being fully overloaded to behave as a normal expression of equivalent structure. Observe: asc = <|"a" -> q, "b" -> r, "c" -> s|>; Block[{q = 1, r = 2, s = 3}, asc] <|"a" -> q, "b" -> r, "c" -> s|> Also: With[{q = 1, r = ...


5

[Not exactly an answer but possibly of interest and definitely too large for the margins..] Another way to do this is to reverse the order of summation. That is to say, there is an implicit sum over integer digits with an outer sum over integers. One could, in a sense, sum over the integers in the inner loop, and over digits in the outer. Well, sort of. ...


4

diameter[x_List] := Max[EuclideanDistance @@@ Subsets[x, {2}]] diameter[pointset] (* 2 Sqrt[5] *) Now, let's improve the performance "a little bit". I believe the maximal distance will be realized at the points' convex hull (I'll not demonstrate it,but it's quite intuitive). Now, if you have a lot of points Mathematica provides a convenient and fast way ...


4

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}]


3

Why not define the expressions in such a way that their dependence on the independent variables is explicit: ClearAll[f, g, x, y] g[x_, y_] = x f[y] + y (* ==> y + x f[y] *) D[g[x, y], y, x] (* ==> Derivative[1][f][y] *) D[g[x, y], x, y] (* ==> Derivative[1][f][y] *) The mixed derivatives now agree.


3

Why not just this? f[l_] := Block[{a,b,c}, a = Length[l]; b = First[l]; c = b/a; c*10] Then f[{2, 3, 4, 5}] 5


2

The method described in File-name completion for custom functions can be used to complete the "description" argument in your examples, but it won't work for the curried parameters and variables. Note that the method does not appear to support dynamic computation of completion choices, so it cannot be used to generate the list directly from a symbol's ...


2

You did not explain (at least to my satisfaction) what this code it supposed to do therefore is hard to give a rigorous answer, but I will attempt to cover multiple issues. First a note: Module[{}, . . . ] is arguably a purposeless construct, one I have no use for and which I remove with every opportunity I get. However at least one very experienced user ...


2

For N[ _, 40] all inputs must have at least that precision. Your definition of Z[1], Z[2], and z[3] use weights with just machine precision. Rationalize the definitions. Z[1] = EmpiricalDistribution[ {0.5, 0.5} -> {0, 1}] // Rationalize; Z[2] = EmpiricalDistribution[ {0.6, 0.4} -> {0, 1}] // Rationalize; Z[3] = EmpiricalDistribution[ ...


2

I'm not sure I understand the question, so will try this to see if it's in the right direction. Consider the following collection of definitions for a function f[ ] f[x_] := x^2; f[x_, y_] := f[x] + y^3; f[x_, y_, z_] := f[x, y] + f[x, z] + Sqrt[z]; f[x_, y_, z_, s_] := x y z s; Every time you add a new parameter, you need only define how you want it to ...


2

Description Today, I know this resourse http://library.wolfram.com/infocenter/MathSource/4557/ accidentally, in this notebook, I find the detailed useage of ListCorrelate,so I post here to share to more Mathematica user that need to improve their capability. Hope I hope sincerely others to edit and check it to make it complete and correct. Statement ...


2

This will probably be closed as a duplicate of either: What are the use cases for different scoping constructs? Passing function as argument In the meantime the simple answer is that you need Module rather than Block, because the former creates a new Symbol whereas the latter merely temporarily changes the value of Symbol. myf = Module[{f}, f[3] = 33; ...


2

That integral can be done analytically: dist[mu_,sd_,kr_] = ProbabilityDistribution[ Assuming[ kr > 0 && sd > 0 && Element[{sd, x, mu, kr}, Reals], Integrate[(Sqrt[a]*sd)^(-1)*PDF[NormalDistribution[0, 1], (x - mu)/(Sqrt[a]*sd)]* PDF[GammaDistribution[kr, kr^(-1)], a], {a, 0, ...


2

The easiest way to accomplish what you ask for requires a some rewriting, but not much. First change your current definition to CentralDifferentMethod[α_, β_, α1_, α2_, λ_, v0_, dt_, t_, u0_] := Module[{sMatrix, mMatrix, dMatrix, disp, velo, accel, index, reff, effStiffnessMatrix}, sMatrix = lumpingMatrix[stiffnessMatrix[α]]; mMatrix = ...


1

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. ...


1

I think it will be difficult to avoid some change to the function. CentralDifferentMethod[α_, β_, α1_, α2_, λ_, v0_, dt_, t_, u0_: False] := Module[{ ...}, If[SameQ[u0, False], disp[0] = u[α, β, λ];(*initial displacement*) disp[0] = u0]; ... Note it is usual to place default values at the end of the input parameters, otherwise it can be ...


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"]


1

Perhaps you can use DiscretePlot3D {alist, blist} = RandomReal[{-2 Pi, 2 Pi}, {2, 20}]; Manipulate[DiscretePlot3D[f[a + b], {a, alist}, {b, blist}, PlotStyle -> Hue[RandomReal[]], ExtentSize -> Scaled[.5]], {f, {Sin, Cos}}]



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