Tag Info

New answers tagged

0

While this has been answered many times, let me answer it once more: varnum = 10; vars = Symbol["a" <> ToString[#]] & /@ Range[varnum]; of = Total[-vars^2 + vars^4]; Minimize[of, vars]


3

I find using Module the easiest way to keep track of things when it comes to these kinds of situations. plot[x_, s_] := Module[{b, w, c, ua, ub}, b = 10 x; w = s + b; c = x^2; ua = w - c; ub = w - c^2; Plot[{ua, ub}, {x, -5, 5}]] plot[randomVar, 5]


6

It comes down to the DRY principle: The DRY principle is stated as "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system." The content management system Wordpress doesn't use object oriented paradigms and so for that reason it looks exactly like your code. Tens of thousands of lines of code like this. ...


3

Initial problem There is, in my opinion, nothing wrong with "multidependences" in the way I think you mean, but there is a more fundamental problem here (I believe). Consider these definitions: w[b_, x_] := fixed + b[x] u[w_, b_, x_] := Sqrt[w[b, x]] I presume that you expect to call u with three arguments and have it in turn call w but this does not ...


16

I see no mention of the new-in-10 PositionIndex in the other answers, which takes a list (or association) of values and returns a 'reverse lookup' that maps from values in the list to the positions where they occur: In[1]:= index = PositionIndex[{a, b, c, a, c, a}] Out[1]= <|a -> {1, 4, 6}, b -> {2}, c -> {3, 5}|> It doesn't take a level ...


2

Clear["Global`*"] g[x_] := x^3 f1[x_] := g[x^2] f2[x_] := g[x^3] Definition@f1 f1[x_] := g[x^2] FullDefinition@f1 f1[x_] := g[x^2] g[x_] := x^3 Head@f1 Symbol Information["f*"] a[1] = 1; a[2] = 2; ?a DownValues@a UpValues@a


13

Good News Everyone! Two-parameter syntax for Fold and FoldList has been (silently) implemented! Taliesin Beynon informs me that this was implemented in 2011, so check your older versions as well. Using version 10: Fold[f, a] FoldList[f, a] f[f[f[1, 2], 3], 4] {1, f[1, 2], f[f[1, 2], 3], f[f[f[1, 2], 3], 4]} And the held expression example: ...


8

I'm the one inside the company who suggested RightComposition (and pushed for syntax for Composition and RightComposition). I'm sympathetic to your need, and have wanted the same thing once or twice myself. Given that not much /* and @* code has been written yet, I think it is certainly possible we could have /* parse to LeftComposition. I'm not sure what ...


6

Using this site as my rubber duck and attempting to answer my own questions: (1) Reason for existing behavior One may want to be able to do this: heldRow = HoldForm @* Row @* List; (* version 10 syntax *) x = 7; Block[{x}, heldRow[x + x + x, x^2*x^3] ] 3 xx^5 (* proposed behavior would yield: x+x+xx^2 x^3 *) My counterargument: this ...


1

I've actually managed to answer it myself - will answer here if it's any good to others; Ebound[r_] = Piecewise[{{Eb1[rn, 14400] /. x, r < rn}, {Eb1[r, 14400] /. x, r > 0}}]; Plot[Ebound[r], {r, 0, ro}, PlotRange -> Automatic] this gives the expected behaviour;


1

A bit more terse than your own code: Symbol /@ ToString /@ Row /@ {{x, y}, {y, z}, {x, z}} {xy, yz, xz} Or using SymbolName as suggested by mfvonh in the comments: Symbol[""<>(SymbolName /@ #)] & /@ {{x, y}, {y, z}, {x, z}} {xy, yz, xz} However, both these and yours will fail if a Symbol such as x already has a value. To get around ...


0

One liner: Table[expr,Evaluate[Sequence@@({#,lim}&/@Array[Subscript[p, #] &, n])]]


0

p0 = Array[Subscript[p, #] &, 7] l0 = Table[1 + Mod[i, 3], {i, 7}] Table[q, Evaluate[Sequence @@ Transpose[{p0, l0}]]]



Top 50 recent answers are included