# Tag Info

11

Clear[first, second, third] names = {first, second, third} numbers = {{1, 1}, {2, 2}, {3, 3}} Table[Evaluate[names[[i]]] = numbers[[i]], {i, 3}] first second third

9

Clear[first, second, third] names = {first, second, third}; numbers = {{1, 1}, {2, 2}, {3, 3}}; With[{names = names}, names = numbers]; first {1, 1}

8

With the following definitions: Clear[first, second, third] names = {first, second, third} numbers = {{1, 1}, {2, 2}, {3, 3}} a one-liner approach would be: Evaluate@names = numbers You can see how this works using Trace: Clear[first, second, third] names = {first, second, third} numbers = {{1, 1}, {2, 2}, {3, 3}} Trace[Evaluate@names = numbers] (* Out:...

7

StringCases["223", a : DigitCharacter ~~ b : DigitCharacter /; Evaluate[Unequal @@ (ToExpression /@ Characters["ab"])]] {23} Compare the evaluation of the three forms using Trace: Trace[StringCases["223", a : DigitCharacter ~~ b : DigitCharacter /; Unequal[ToExpression /@ Characters["ab"]]] ] // Column Trace[StringCases["223", a : ...

6

MapThread works well for this task. numbers = {{1, 1}, {2, 2}, {3, 3}}; Clear[first, second, third] names = {first, second, third}; MapThread[Set, {names, numbers}]; {first, second, third} {{1, 1}, {2, 2}, {3, 3}}

5

Use := and not = bad[u_?NumericQ] := Module[{func}, func[v_?NumericQ] := Module[{y}, y = u v; Switch[Sign[y], 1, y, -1, y + 1, 0, 1] ]; NIntegrate[func[k], {k, 0, 1}] ]; bad (* 1 *) Without delay, func[k] evaluated right away, and hence it had no numerical values for the Switch to behave as expected. For the good example, you had no ...

5

Still another approach is Clear[REL1, RAND1, n1]; n1 = {{REL1, "REL.csv"}, {RAND1, "RAND.csv"}}; Set @@ First[n1]; which yields {REL1, RAND1} (* {"REL.csv", RAND1} *) as expected. To perform this process on the whole list, use Clear[REL1, RAND1, n1]; n1 = {{REL1, "REL.csv"}, {RAND1, "RAND.csv"}}; Set @@@ n1; which yields {REL1, RAND1} (* {"REL.csv",...

5

Not really a mathematica problem but here is something to get you going in the Wolfram Language. eqn = x''[t] + (2 π 100)^2 x[t] == f[t]; ic = {x' == 0, x == 0}; f[t_] := Sin[110 2 π t]; sol = NDSolve[Join[{eqn}, ic], {x}, {t, 0, 0.2}]; Plot[Evaluate[x[t] /. First[sol]], {t, 0, 0.2}] Here I have made an oscillator with a natural frequency of 100 Hz ...

4

Use With. It will inject the pre-calculated value of the larger Subsets expression in your definition, but without “messing up” the readability of your code: ClearAll[inversions] With[ {SUBSETS = Subsets[{1, 2, 3, 8, 4, 7, 6, 5}, {2}]}, inversions[list_] := Complement[SUBSETS,Subsets[list, {2}]] ] You can check that downvalues (i.e. the definition) of ...

4

Mathematica is correct. In general, there will only be the trivial solution. You are trying so solve an equation $M x = b$ with $b= 0$. This will have a nontrivial solution if and only if $\mathrm{det} M = 0$, because otherwise the matrix can be inverted, i.e. there exists a matrix $M^{-1}$ such that $M M^{-1} = M^{-1} M = I$, where $I$ is the identity ...

4

You can use a pure function to store the boolean expression: var = # == "a" &; You can use it with PatternTest Select[{"abc", "def"}, StringMatchQ[StartOfString ~~ c1_?var ~~ __ ~~ EndOfString]] {"abc"} or with Condition: Select[{"abc", "def"}, StringMatchQ[StartOfString ~~ c1_ ~~ __ ~~ EndOfString /; var[c1]]] {"abc"}

3

You can do this using replacements by replacing List with Set. For example: n1 = {{REL1, "REL.csv"}, {RAND1, "RAND.csv"}}; Evaluate[n1[] /. List -> Set] Now REL1 is REL.csv You can do a whole list of such things: Clear[REL1, RAND1]; n1 = {{REL1, "REL.csv"}, {RAND1, "RAND.csv"}}; Table[Evaluate[n1[[i]]] /. List -> Set, {i, Length[n1]}]

3

Please try this code. Assuming it works for you feel free to ask for clarification as needed. f = a*Cos[x] + b*Sin[x]; vars = Variables @ Level[f, {-1}]; pats = Pattern[#, _] & /@ vars; g[pats] = f; coeff = DeleteCases[vars, x]; ranges = {#, 0, 1} & /@ coeff; With[{body = g[vars]}, Manipulate[PolarPlot[body, {x, 0, 2 Pi}], ##] & @@ ranges ...

3

I used to do this with NotationSymbolize, but it had some shortcomings like, if you save expressions on disk and later load into another notebook, then symbolization is not preserved automatically, and you end up with lots of names with \[UnderBracket] in them. Even more important, you cannot create a list of symbolized indexed variables by just using Table[...

2

Since inc is 65536 and BaseForm[inc, 2] is 10000000000000000, accu will always be zero. You can see this by observing the calculations samplingRate = 500; seconds = 1/5; bits = 16; maxV = 2^bits; freq = 500; samples = samplingRate seconds 100 inc = maxV freq/samplingRate 65536 BaseForm[inc, 2] Then, of course, BitAnd[inc, 255] gives zero ...

2

Manipulate[Sum[cs[[i]], {i, n}], {{cs, ConstantArray[0, 10]}, ControlType -> None}, {{n, 1, "n"}, 1, 10, 1, Appearance -> "Labeled"}, Dynamic[Grid[Table[With[{i = i}, {Symbol["c" <> ToString[i]], Checkbox[Dynamic[cs[[i]]], {0, 1}]}], {i, n}]]]]

2

You can do the first one: Row[{Superscript[" ", "*"], M}] and the second by Superscript[M, "*"] and if you want the equals sign at the end: Row[{Superscript[M, "*"], "="}] You can replace the * with anything you wish.

2

a := 5 x list = {} x = 1 b = a AppendTo[list, b] (*{5}*) x = 2 b = a AppendTo[list, b] (*{5, 10}*)

2

e = {1, 0, 0, 1}; SymbolName[Unevaluated[e]] Result: e Another option, if to be used inside a function (as noted in your comment), would be to design the function to accept the symbol name instead of the symbol (or require both to make things clearer). Here is a version with just the symbol name. The symbol is extracted in the function. x = 5; Plus5[...

2

HoldForm[] is surely an important ingredient. The other important bit is that whatever function you write should have an attribute like HoldFirst or HoldAll to prevent premature evaluation. As a simple example: SetAttributes[gg, HoldFirst]; gg[x_Symbol] := Column[{Row[{HoldForm[x], "="}], x}] Then, ff = {1, 1, 0, 1}; gg[ff] ff= {1, 1, 0, 1}

2

But this variable SUBSETS is used for only the function inversions, and thus should've been bound to this function, instead of dangling in the global scope like this You could put the stuff inside some new context? From clean Kernel Begin["myStuff"] SUBSETS = Subsets[{1, 2, 3, 8, 4, 7, 6, 5}, {2}]; inversions[list_] := Complement[SUBSETS, Subsets[...

1

Clear["Global*"] soln = NDSolve[{x'[s] == -z[s] - x[s]^2, z'[s] == 2 x[s] - z[s]^3, x == z == 1}, {x, z}, {s, 0, 20}] Plot[Evaluate[{z[s], x[s]} /. soln], {s, 0, 20}, AxesLabel -> {Style[s, 14, Bold], None}, PlotLegends -> Placed[ (Style[#, 14, Bold] & /@ {z[s], x[s]}), {0.5, 0.1}]] As in this case, x[s] would likely be ...

1

It would certainly be easier to specify the values of the variables independently. They appear together in the expression in several different ways. Uz // FullForm reveals the underlying expression. Looking for the products of k and R, we find Times[Complex[0, Rational[-1, 2]], Power[k, -1], Power[R, -1], Plus[Times[Power[k, 2], Power[R, 2]] and Power[...

1

Applying set at level 1 n1 = {{REL1, "REL.csv"}, {RAND1, "RAND.csv"}}; (#1 = #2) & @@@ n1; {REL1, RAND1} {"REL.csv", "RAND.csv"}

1

ClearAll[REL1, RAND1]; n1 = {{REL1, "REL.csv"}, {RAND1, "RAND.csv"}}; (Evaluate@First@# = Last@#) & /@ n1; {REL1, RAND1} (* {"REL.csv", "RAND.csv"} *)

1

You actually have to set phi c, as in c = c /. Solve[... , c]

1

You can use Names to list the variables and OwnValues to get the value that they store. Namely GetDefinedVariables[] := Module[{allrules}, allrules = ToExpression["OwnValues[" <> # <> "]"] & /@ Names["Global*"]; Replace[allrules /. RuleDelayed -> Sequence, {} -> Nothing, 1] ]; The second line simply puts the result into tuples, ...

1

plot[reg_,f_] := Module[{tr=Transpose,d=Length@reg,n=Length@f[],v,o}, v = Table[Unique[],{i,d}]; o={f@@v,Sequence@@tr@Prepend[tr@reg,v],PlotRange->All}; If[n==2,Return[ParametricPlot@@o]]; If[n==3,Return[ParametricPlot3D@@o]]; ];

1

I was wrong in the comments, since you have an analytical expression for θ, there is no need for an InterpolationFunction. f[y_, θ_] = 2 y Cos[θ] + 4 y^2 (1 - 3 Cos[θ]); gradf[y_, θ_] = Grad[f[y, θ], {y, θ}]; v0 = f[y, θ]/gradf[y, θ]; There was a typo, the Cos didn't have brackets in the first line, also I added v0 to save the evaluated expression before ...

1

Here is an alternative, unless I got your question wrong, but tbh I am not sure I know what you want: rule[n_] := Module[{body}, body = Product[Sprod[Slot[i], Slot[i + 1]], {i, 1, n}]; Function @ Evaluate @ body ] rule Sprod[#1, #2] Sprod[#2, #3] & f = rule; f[a, b, c] Sprod[a, b] Sprod[b, c]

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