Skip to main content
23 votes

Extracting variables from an expression

Using an undocumented function: ...
J. M.'s missing motivation's user avatar
14 votes
Accepted

How to transform a function from f[#1] to f[x]

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 ...
John Doty's user avatar
  • 14k
13 votes
Accepted

When to name a variable with $

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

How to transform a function from f[#1] to f[x]

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 ...
Ulrich Neumann's user avatar
11 votes

For any symbol, how can I get the full context-qualified name of the symbol as a string?

This is a variation of Leonid's answer that avoids the dependence on a context like "Test`" that must be empty: ...
ilian's user avatar
  • 25.5k
11 votes

General::ivar 0 is not a valid variable when using Series in Plot

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 / ...
Kuba's user avatar
  • 138k
11 votes
Accepted

Name a list with Table

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
LouisB's user avatar
  • 12.8k
10 votes
Accepted

Map[Remove[#]] doesn't seem to do anything

As stated in the comments, a is evaluated before being fed into Remove. We can prevent this by using ...
Greg Hurst's user avatar
  • 36.8k
10 votes
Accepted

Is it possible for Mathematica to output the name of a matrix as opposed to its matrix form?

You can decompose any Hermitian 2ร—2 matrix $A$ into a sum over Pauli matrices, $$ A=c_1\mathbb{1}+c_x\sigma_x+c_y\sigma_y+c_z\sigma_z $$ and the coefficients $(c_1,c_x,c_y,c_z)$ can be computed by the ...
Roman's user avatar
  • 49.8k
9 votes
Accepted

Apply ToString to a list of variables

In addition to Mr.Wizard's answer here is a collection of other possibilities: ...
Alexey Popkov's user avatar
9 votes
Accepted

Context inside Do[...]-loop

Begin["mycontext`"] affects the parser, not the evaluator. These are separate expressions: Begin["mycontext`"]; ...
Szabolcs's user avatar
  • 236k
9 votes
Accepted

Why is DSolve different when the equation is built programmatically?

You attempt to solve the ODE at the time of definition of lsolve. At this point, q does not depend on ...
Henrik Schumacher's user avatar
9 votes

Name a list with Table

Clear[first, second, third] names = {first, second, third}; numbers = {{1, 1}, {2, 2}, {3, 3}}; With[{names = names}, names = numbers]; first {1, 1}
Chris Degnen's user avatar
  • 31.3k
9 votes

Partial derivatives in a variable name

I suggest using any of the other similar-looking characters: U+1D6DB ๐›› U+1D715 ๐œ• U+1D74F ๐ U+1D789 ๐ž‰ U+1D7C3 ๐Ÿƒ all of which seem to produce a valid symbol in Mathematica.
Domen's user avatar
  • 33.4k
9 votes
Accepted

How to Obtain Complete List of Properties

Importing "MTX" returns a SparseArray, so you can do A["Properties"]. ...
rhermans's user avatar
  • 37.4k
8 votes

Character to replace _ in symbol names?

I use $ as a separator. It is a valid symbol character. In my application I have a set of variables that need to be identified by coordinates, like for example a17_4_25. I can't just drop the _ ...
Shebla Tsama's user avatar
8 votes

Name a list with Table

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: <...
MarcoB's user avatar
  • 67.7k
7 votes
Accepted

Want to return name of last defined variable without explicitly naming it

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 ...
Michael E2's user avatar
  • 245k
7 votes
Accepted

Is it possible to "escape" numbers so they can be used as a variable name?

YES. Use Script Numbers like ScriptThree \[ScriptThree]=4
Kelly Lowder's user avatar
7 votes
Accepted

Name of patterns cast as expressions from strings

StringCases["223", a : DigitCharacter ~~ b : DigitCharacter /; Evaluate[Unequal @@ (ToExpression /@ Characters["ab"])]] ...
kglr's user avatar
  • 401k
7 votes

Construct 1 variable function from given 2 variable function

What you want is called "currying". Not involving new operators you may try: ...
Daniel Huber's user avatar
  • 56.4k
7 votes
Accepted

Make matrixes with numbered name

You can use ToString and ToExpression to form the variable names and make assignments to them. Variable names: ...
Anton Antonov's user avatar
7 votes
Accepted

Incorrect syntax highlighting? "Variables made special by use in arguments" not working

Welcome to MMA SE! (Note that I think you shouldn't be using Evaluate there: consider i=3; Do2[Print[i], {i,5}].) Syntax ...
thorimur's user avatar
  • 9,080
7 votes
Accepted

How to use <* *> in tex to substitute mathematica variables

I haven't saved it. Well, if you do not save the latex to the file, it will not work. Here is a small template to use. This creates index.tex file, solves few integrals and solves an ode and saves ...
Nasser's user avatar
  • 150k
7 votes

Does Mathematica have that function which returns the variables back

Edit Thanks @BobHanlon ...
cvgmt's user avatar
  • 84.1k
7 votes

Is it possible for Mathematica to output the name of a matrix as opposed to its matrix form?

This is a partial answer addressing only the first example given. If you Set the value of a symbol, the symbol can never appear in the output, only its value. ...
Bob Hanlon's user avatar
  • 163k
6 votes

Apply ToString to a list of variables

You're going to first need to hold {data1,data2} unevaluated in some way; either define it first, use SetDelayed (short form <...
Mr.Wizard's user avatar
  • 273k
6 votes
Accepted

Can I bake my own PI using your Wolfram language oven and prebuilt utensils?

Beside using Block as ciao suggests in his comment to the question, you can also play with the attribute Protected. Thus, <...
m_goldberg's user avatar
  • 108k
6 votes

From f[g[x,t]] to f[g]

f[g[x,t],t] /. g[___]->g (* f[g, t] *)
Roman's user avatar
  • 49.8k
6 votes

Name a list with Table

MapThread works well for this task. ...
m_goldberg's user avatar
  • 108k

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