# Tag Info

16

Using an undocumented function: ReduceFreeVariables[(mc dm^2 + mc/12*(h^2 + 3 R^2) + ma da^2 + ma/12 La^2)/ (mc dm + ma da)] {da, dm, h, La, ma, mc, R}

14

Well, the easy way is to evaluate it for [x,y]. f[x_, y_] = Sqrt[-1 + Tanh[#1 - #2]^2] &[x, y]; If you'd rather do it with a replacement, you should understand the FullForm because that's what replacement works on. Sqrt[-1 + Tanh[#1 - #2]^2] & // FullForm (* Function[Sqrt[Plus[-1,Power[Tanh[Plus[Slot,Times[-1,Slot]]],2]]]] *) So, you want ...

13

13

A few examples fun[x_] := x^2 sphere = Graphics3D[{Sphere[{0, 0, 0}, 0.01]}, Boxed -> False, ImageSize -> 30]; str = {"1", "Pi", "{f}", "f", "f[x]", "f+f", "Inactivate[f+f,Plus]", "Hold[1+2+3]", "{1,{2,{3}}}", "fun", "fun[x]", "Cos[Exp[x]]", "Red", "sphere", "DateObject[{2014,10}]"}; table = With[{exp = ToExpression /@ str}, ...

13

Look at the system context to see what the convention is. I can find 257 built-in symbols in 11.3, symbols = Names["System$*"]; Length @ symbols (* 257 *) In the system context there seems to be two main uses of the$ naming convention. It is used for static symbols without value, that can indicate e.g. evaluation status, like $Aborted,$Failed, $Canceled,... 13 I think the easiest way would be to define(name) the pure function f f = Sqrt[-1 + Tanh[#1 - #2]^2] & and use it accordingly f[x,y] (*Sqrt[-1 + Tanh[x - y]^2]*) 11 This is a variation of Leonid's answer that avoids the dependence on a context like "Test" that must be empty: SetAttributes[fq, {Listable, HoldAll}]; fq[sym_] := Block[{Internal$ContextMarks = True},ToString[Unevaluated[sym]]] fq[{fq, Print, Developer$MaxMachineInteger}] (* {"Globalfq", "SystemPrint", "Developer$MaxMachineInteger"} *)

11

Using an undocumented function: ReduceFreeVariables[u] === Sort[vas]

11

There are couple of problems with your code. It is an image, it would be way nicer not to have to rewrite it. Plotting Series If you go to ref / Series / Application you will see that Normal is used to plot a Series as otherwise O[x]^n will make Plot confused. Function definition Functions are defined more or less like that f[x_]:=... but if x is an ...

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

10

I suspect it's an internal decision by WRI to allow as variables only expressions of the form A[0, 1, 2], that is, a symbol with integer arguments. You could try reporting your desired functionality to WRI; maybe they will extend what expressions are allowed. Instead of being localized in the usual way, the expressions are remapped to Unique[] symbols. For ...

10

Update Following your updated question I recommend filtering Level output with Variables as I proposed here. Then Sort vas and check for equivalence. Sort[vas] === Variables @ Level[u, {-1}] Original proposals The first idea that came to mind: Level[u, {-1}] ⋂ vas === Sort[vas] Equivalently: Complement[vas, Level[u, {-1}]] === {} A method using ...

9

Here's a way: var1 = 10; var2 = 11; var3 = 17; var4 = 5; compvar := {var1, var2, var3, var4} compvar; (*all variables assigned*) ClearAll[f]; SetAttributes[f, {HoldAll}]; f[x_, y__] := Flatten@{f[x], f[y]} f[x_] := SymbolName@Unevaluated@x OwnValues[compvar] /. {HoldPattern[y_] :> {x__}} :> f[x] (* {"var1", "var2", "var3", "var4"} *)

9

This is really easy if you understand the internal form of {a,b,c,d}. Let's look at it: p={a,b,c,d}; FullForm[p] (* List[a,b,c,d] *) as you see what you want is not really far away because basically, you only need to replace List with f. This is exactly what Apply (or as operator @@) does: f @@ p (* f[a, b, c, d] *)

9

As stated in the comments, a is evaluated before being fed into Remove. We can prevent this by using Unevaluated: a = 1; b = 2; c = 3; Remove /@ Unevaluated[{a, b, c}]; a a One can also use Apply instead of Map to effectively achieve Remove[a, b, c]: a = 1; b = 2; c = 3; Remove @@ Unevaluated[{a, b, c}]; a a

9

In addition to Mr.Wizard's answer here is a collection of other possibilities: data1 = {1, 1}; data2 = {2, 2}; datalist := {data1, data2}; ToString /@ Map[HoldForm, OwnValues[datalist], {3}][[1, 2]] ToString /@ Map[Unevaluated, OwnValues[datalist], {3}][[1, 2]] ToString /@ Thread[HoldForm[datalist] /. OwnValues[datalist]] ToString /@ Thread[Extract[...

9

Begin["mycontext"] affects the parser, not the evaluator. These are separate expressions: Begin["mycontext"]; myvar = 7; Print[Context[]]; Print[Context[myvar]]; End[]; They get parsed and evaluated one by one. Once Begin["mycontext"]; is evaluated, the new context applies to all subsequent lines. This is a single expression: Do[ Begin["...

9

You attempt to solve the ODE at the time of definition of lsolve. At this point, q does not depend on x. You really want to use SetDelayed here: lsolve[r_, q_, a_, eta_] := y[x] /. First@DSolve[{y'[x] == r - q*y[x], y[a] == eta}, y[x], x]; nwe = lsolve[x, 2*x, 0, 0] // Simplify 1/2 - E^-x^2/2

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

There's also Defer to accomplish this: varname = 1; Defer @ varname varname

7

You must introduce some form of holding in you definition of compvar as otherwise, assuming it is defined after var1, var2, etc., there is no information to retrieve: var1 = 10; var2 = 11; var3 = 17; var4 = 5; compvar = {var1, var2, var3, var4}; Definition[compvar] compvar = {10, 11, 17, 5} You could use Hold but then you would need to ReleaseHold (or ...

7

Remember that = is really Set, and Set is a pretty ordinary function. Also, RandomInteger can make a list all by itself, so you don't need Table. Edit 11/15: Jerry Guern pointed out the need to be careful with quoting to have it work repeatedly. Here, I use Unevaluated to quote each variable: r = Unevaluated /@ {a, b, c, d, e, f, g, h, i}; Now, you may ...

7

I think there must be a better way to accomplish the OP's ultimate goal than the general approach outlined above. But be that as it may, the following culls all the Set[] commands from the last input line (so it has a little broader scope than what was asked for). lastInputSets[] := Block[{Set}, Grid@Cases[Hold[In[#]] &[\$Line - 1] /. DownValues[In], ...

7

YES. Use Script Numbers like ScriptThree \[ScriptThree]=4

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

7

What you want is called "currying". Not involving new operators you may try: Clear[f, g] f[x_, y_] := x^2 + y^3 g[x_] = Evaluate[f[x, #]] &; f[3, 2] == 17 == g ?? g However, MMA has a special operator CurryApplied for this: Clear[f, g] f[x_, y_] := x^2 + y^3 g = CurryApplied[f, 2]; f[3, 2] == 17 == g ?? g You may want to also ...

7

You can use ToString and ToExpression to form the variable names and make assignments to them. Variable names: varNames = Table["M" <> ToString[i], {i, 12}] (* {"M1", "M2", "M3", "M4", "M5", "M6", "M7", "M8", "M9", "M10", "M11", &...

7

Welcome to MMA SE! (Note that I think you shouldn't be using Evaluate there: consider i=3; Do2[Print[i], {i,5}].) Syntax highlighting is done in terms of the syntax only, and the front end's processing of that syntax; the downvalue of Do2 (that is, the definition you gave it via :=) is not a syntactic property the front end can access. But there is a way to ...

6

This is an example of unintended behavior in Mathematica that the developers are aware of. There are a number of workarounds. The simplest is to wrap a function around the appropriate bounds; instead of Manipulate[m, {n, {10}}, {m, n - 1, 2 n, 1}] which illustrates the problem, try Manipulate[Floor@m, {n, {10}}, {m, n - 1, 2 n, 1}] A solution can also ...

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