# Tag Info

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

0

You guessed right that one problem in your code is the missing definition of V. In the snippet you posted above, you defined a function V[X_, Y_, Z_, Len_, Br_, Dep_]. Later, you try to call it by writing D[V, x]. This does not work, because Mathematica distinguishes between V and V[X_, Y_, Z_, Len_, Br_, Dep_]. You can see this by looking into the down ...

1

Assuming $G=\rho=1$, move the gradient operator into the integral:  \begin{align} - \mathbf{g} = \nabla V(X,Y,Z) &= \nabla \int_{-D}^{D} \int_{-B}^{B} \int_{-L}^{L} \frac{{dx}'{dy}'{dz}'}{\sqrt{(X-{x}')^2+(Y-{y}')^2+(Z-{z}')^2)}} \\ &= \int_{-D}^{D} \int_{-B}^{B} \int_{-L}^{L} \nabla ...

1

Simplest solution Use Set instead of SetDelayed: vl = {a_, m_, s_, τ_, c_, x$HH_, x$HF_, x$FF_, x$FH_, λ$H_, λ$F_, L$H_, L$F_, w_, δ_}; vle = {a, m, s, τ, c, x$HH, x$HF, x$FF, x$FH, λ$H, λ$F, L$H, L$F, w, δ}; vle1 = {1, 1, 1, 1, 1, 1, 1, x$FF, x$FH, λ$H, λ$F, L$H, L$F, w, 1}; xx[vl] = vle; xx[vle1] xx[2 vle1] (* {1, 1, 1, 1, 1, 1, 1, x$FF, x$FH, λ$H, λ$F, ...

2

This approach seems to work. Clear@f list = {a, b, c} argList := Evaluate@ Sequence @@ (Pattern[#, Blank[]] & /@ list) f[argList] := a + b + c DownValues@f (* {HoldPattern[f[a_, b_, c_]] :> a + b + c} *) f[1, 2, 3] (* 6 *) I think it fits your request. If not, maybe try manipulating DownValues[f] directly, but it won't be elegant! Edit: ...

0

You are using insufficient precision: theta2'[.8] (* -0.794774 + 0.280078 I *) Precision[.8] (* MachinePrecision *) Use exact arguments: theta2'[8/10] and get the exact result. Use N et. al. with desired precision to retrieve numeric values. N[theta2'[8/10], 10] (* -0.8874928427 + 4.596*10^-7 I *)

0

This is mimicking the OP code, flipping every instance of the chosen values at each iteration.. You can set your chosen pair to anything you like and the procedure will result in all equal: w = {10, 20, 74, 77, 19, 79, 61, 67, 49, 85}; NestWhile[# /. ((Table[#[[1, i]] -> #[[2]] , {i, 2}] ) &@ { RandomChoice[#, 2] , RandomInteger[100]}) & , ...

2

My take on the question: w = {10, 20, 74, 77, 19, 79, 61, 67, 49, 85}; picks = RandomChoice[Range@Length@w, {1000, 2}]; iterations = Reap[Do[If[(Sow[{w, pick, Max[Tally[w][[All, 2]]]}]; Equal @@ w), Break[], If[Abs[Subtract @@ w[[pick]]] < 50, w[[pick]] = Round[Mean[w[[pick]]]], w[[pick]] = Round[(99 + Tr@w[[pick]])/2 - ...

2

For clarity I would suggest defining a function to create the new value from 2 integers. newvalue[{x_, y_} /; Abs[x - y] < 50] := Round[Mean[{x, y}]] newvalue[{x_, y_}] := Round[(x + y + 99)/2 - 99] w = {10, 20, 74, 77, 19, 79, 61, 67, 49, 85}; n = Length[w]; While[! Equal @@ w, Pause[0.1]; With[{p = RandomInteger[{1, n}, 2]}, w[[p]] = ...

2

Interesting problem. It shows the effect of diffusion which gradually smoothes an initially existing structure. Here is a possible code. I think it is mainly self explanatory; hence only a few hints are given. wlg = 15; (* length of the array *) r := RandomInteger[{1, wlg}] (* a random position in the array *) nn = 10^2; (* number of repetitions of the ...

1

Perhaps something like this? w = {10, 20, 74, 77, 19, 79, 61, 67, 49, 85}; While[Not[Equal @@ w], Print[w]; {xi, yi} = RandomSample[Range[Length[w]], 2];(*Pick 2 different locations*) w[[{xi, yi}]] = Round[Mean[w[[{xi, yi}]]]];(*Replace both with the mean*) ]; Print[w]

2

I didn't try to follow your code, but I think this is what you're asking for w={10, 20, 74, 77, 19, 79, 61, 67, 49, 85}; replaceWithMean[x_] := Module[ {pair,intMean}, pair = RandomInteger[{1, Length@x}, {2}];(*2 Random positions in list*) intMean = Round[Mean[x[[pair]]],1]; (*Mean of selected numbers rounded to nearest 1*) ReplacePart[x ...

4

Reap has the attribute HoldAll. This is necessary so that its argument is not evaluated until Reap has set up the conditions necessary to capture the values designated by Sow. The implementation of @* (Composition) is such that it interferes with the attributes of the right-most composed function. In the exhibited example, the Sow expression is evaluated ...

0

The symbol _ is a shortcut for Blank[]. If you try evaluating Blank[] === True your result will be False, so your third condition can never be met. If you need an expression for your third condition that will always evaluate to True, I can think of a good one that works pretty well: Which[ x === 1, "AAA", x === 2, "BBB", True, $Failed ] 1 The first bit of housekeeping I'll do is prevent the notebook from miniaturising super-/sub-scripts so I can see what is going on. SetOptions[EvaluationNotebook[], ScriptSizeMultipliers -> 1] Next I'll enable a new symbol$a_i$by using the Notations package. Needs["Notation"] Symbolize[ParsedBoxWrapper[SubscriptBox["a", "_Integer"]]] The Symbolize ... 1 Just to illustrate (using testList definition given) : c1 = Cases[#, {_?PrimeQ, _}, Infinity] & /@ testList; c2 = Select[#, PrimeQ[First@#] &] & /@ testList; c3 = Pick[#, Map[Function[x, PrimeQ[First@x]], #]] & /@ testList; and for the ridiculous: c4 = Flatten[Last[Reap[Sow[{##}, #1], _?PrimeQ, #2[[1]] &]]] /. {} -> ... 3 I think you can move condition outside brackets: ClearAll[f]; f[x_Integer : 1] /; x >= 0 := {x} 1 Here is another way using Cases Cases[#, {x_, y___} /; PrimeQ[x] :> {x, y}] & /@ testList Versification with Map method given by Taiki testList = Table[Table[{i, RandomReal[]}, {i, 10}], {j, 1, 3}]; Function[arg, Select[arg, PrimeQ[#[[1]]] &]] /@ testList Cases[#, {x_, y___} /; PrimeQ[x] :> {x, y}] & /@ testList 4 Use the pure function in the form of Function[x, ...] or Function[{x, y}, ...] for more arguments. For example, Function[arg, Select[arg, PrimeQ[#[[1]]] &]] /@ testList 3 this would be a definition which does what you want for a list of rules: f[r : {__Rule}] := someFunction @@@ r and this would be one which handles the Association case: f[a_Association] := someFunction @@@ Normal[a] As mentioned by Gerli in a comment in version 10.1 one can also use KeyValueMap for the second case, for which that new function was ... 2 r = {"a" -> "1", "b" -> "2", "c" -> 3, d -> 231, "e" -> 1.25}; someFunction[key_, value_] := {key, value}; (* say *) f = someFunction @@@ # & f@r {{"a", "1"}, {"b", "2"}, {"c", 3}, {d, 231}, {"e", 1.25}} 4 What you experience is not Mathematica not dealing with 0.02 correctly, but your yy[...] being called with arguments, for which it is not defined. The following modification will show you the reason: yy[x_, t_]:= Which[x == 0, yy[0, t] = 0, x == 1, yy[1, t] = 0, t == 0, yy[x, 0] = Exp[-1000 (x - .3)^2], True, Print["x==", x, " t==", t];"yy[" ... 2 I take it you are interested in the minimum in the absolute value of the difference Abs[f[x]-c g[x]]. Otherwise, the answer is trivial: c=-Infinity. Let us define the functions: f[x_] := (-1 + x) Log[1 - x] - x Log[x]; g[x_] := Log[1 + 2 (-1 + x) x]; w[x_, c_] := f[x] - c*g[x]; and plot them: Manipulate[Plot[w[x, c], {x, 0, 1}], {c, -3, -0.1}] ... 3 Before I begin, a quick note. In the problem as stated, the optimal value of c is$-\infty$, since that makes the value of$f-(-\infty)g=f-\infty=-\infty$(since$g<0$for all$x\in(0,1)$). I'll instead work the problem of minimizing$|f-cg|\$. First we can evaluate the Maximize statement, just to see what we get: Maximize[{Abs[f[x] - c g[x]], 0 < x ...

1

Example 3 is very different from example 1 and 2. Example 2 is a function with 4 arguments whereas example 3 has two arguments, first argument is a list with three elements{a_,b_,c_} and 2nd argument is r. Function names are in Mathematica not only defined by their names but by their name,structure of arguments and the names of the arguments. ...

2

You have make your own definitions to handle non-commutativity. The basic trick is to use op[x1, x2, x3, ...] to represent an operator product, and to define various rules for manipulating the op[x1, x2, x3, ...]. To solve your problem I find that the minimum set of rules is as follows (using an obvious notation): Clear[op]; op[u___, x_ + y_, v___] := ...

Top 50 recent answers are included