6 votes
Accepted

How to define variables $a$,$b$,$c$,$d$ are all elements of set $\{2,3,5,7\}$?

And @@ Or @@@ (Thread[# == {2, 3, 5, 7}] & /@ {a, b, c, d}) ...
cvgmt's user avatar
  • 54.2k
6 votes
Accepted

Get the symbol name of the function's nth argument

The following does what you want: SetAttributes[Plo,HoldAll] Plo[fun__]:=SymbolName@@{Unevaluated@@Hold[fun][[{2}]]} Besides some cleanup of your function, the ...
Lukas Lang's user avatar
  • 32.2k
6 votes
Accepted

Repeating definitons of variables

no no, I want 3/2 as the answer. I just want it to print the answers 3/2, 7/5, 17/12, 41/29... One of 10 possible ways ...
Nasser's user avatar
  • 130k
6 votes

How can I make 10 variables from a for loop?

You might find it easier to do For[i = 0, i < 4, i++,b[i]=0] b[3] (* gives 0 *)
evanb's user avatar
  • 5,699
5 votes
Accepted

How to directly define a function as the solution of RSolve

To make my comment clear, here is the full code: ...
Daniel Huber's user avatar
  • 40.7k
5 votes

Repeating definitons of variables

Clear["Global`*"] y = 1; x = 2; n = 2; NestList[(#^(x - 1) + n)/(#^(x - 1) + #^(x - 2)) &, y, 6] EDIT If the same definition must be used and kept, ...
Syed's user avatar
  • 32.3k
5 votes
Accepted

SystemModelLinearize

Too long for comment, but can you use these replacements for your symbolic variables? If not, then add a desirable output for A and ...
Syed's user avatar
  • 32.3k
5 votes
Accepted

Very simple, unexpected Low Performance of set(=)

I assume that, like all modern software, Mathematica implements copy-on-write. From the Wikipedia: Copy-on-write (COW), sometimes referred to as implicit sharing or shadowing, is a resource-...
Roman's user avatar
  • 43.6k
4 votes

Can you use superscripts as variable and function names?

ClearAll["Global`*"] Format indexed variables ...
Bob Hanlon's user avatar
  • 144k
4 votes

Repeating definitons of variables

Following Syed's idea, another way to do this is to use FoldList: ...
E. Chan-López's user avatar
3 votes

How to implement Newton's Identities

It's not clear whether you need just a display or formal expression or an actual recursive function. I'll assume the latter. ...
lericr's user avatar
  • 18.4k
3 votes

How to implement Newton's Identities

...
azerbajdzan's user avatar
  • 5,935
3 votes
Accepted

My ParallelDo does not work

Part 1. Compare Tr1[A_,B_]:=Tr[ConjugateTranspose[A].B]; Tr2[A_,B_]:=With[{X=Most[ArrayRules[A]]},Conjugate[X[[;;,2]]].Extract[B,X[[;;,1]]]]; They give the same ...
user293787's user avatar
  • 11.7k
3 votes

Repeating definitons of variables

The formula is a recursion, and so can be written: Clear[y]; x = 2; n = 2; y[1] = 1; y[k_] := y[k] = (y[k - 1]^(x - 1) + n)/(y[k - 1]^(x - 1) + y[k - 1]^(x - 2)) ...
bill s's user avatar
  • 67.5k
3 votes

Repeating definitons of variables

x = 2; n = 2; The general solution is ...
Bob Hanlon's user avatar
  • 144k
3 votes
Accepted

Implement recursion one step at a time with a function of more than one variable

The rule won't fire because of the signature issue (f[3] vs. f[3,x]). And there will be no end to the recursion as currently ...
Daniel Lichtblau's user avatar
3 votes

How can I make 10 variables from a for loop?

You could use ToExpression ...
Nasser's user avatar
  • 130k
3 votes
Accepted

How to define functions using $Z_2$ coefficients and $Z_N$ variables, e.g, realizing $1+1=0$?

Method 1. One could use ...
user293787's user avatar
  • 11.7k
3 votes
Accepted

Defining function for decimal value k[0.5+0.5]

Can you explain this phenomenon? May be this will help explain it? ClearAll[k] k[0.5 + 0.5] = 1; k[1] ...
Nasser's user avatar
  • 130k
3 votes
Accepted

How to avoid using the principal branch?

How can I make Mathematica to use Log[−1]=iπ+2iπ∗n with n∈Z? I would not advice doing this but you can do Log[-1] ...
Nasser's user avatar
  • 130k
2 votes

How to define variables $a$,$b$,$c$,$d$ are all elements of set $\{2,3,5,7\}$?

One idea is to use Element with the Region primitive Point. Let ...
Carl Woll's user avatar
  • 127k
2 votes

How to define variables $a$,$b$,$c$,$d$ are all elements of set $\{2,3,5,7\}$?

Or another Alternatives And@@Thread[{a, b, c, d}==Alternatives@@{2, 3, 5, 7}] ...
rhermans's user avatar
  • 35.6k
2 votes

Get the symbol name of the function's nth argument

I'm not sure what the "nth" argument is supposed to be, since n does not appear in the OP, just 2. So here's a way to ...
Michael E2's user avatar
  • 229k
2 votes

Different strategies to get a clean Kernel. Quit, Exit, ClearAll, Remove, CleanSlate?

Cleaning This is a Community Wiki answer, experienced users are welcome to add to it and correct mistakes. Most of the solutions are already listed in the question. ...
2 votes

Why modules with no variables?

CompoundExpression If I need to group expressions I prefer the use of the FullForm of CompoundExpression, i.e. to use ...
rhermans's user avatar
  • 35.6k
2 votes
Accepted

The way of converting a string to a variable in a loop?

In this example data is cleared in advance for reruns. Clear[name] clears name not data so Apply is used. ...
Chris Degnen's user avatar
  • 30.5k
1 vote

Function definition inside Module with local symbol

Try evaluating just Module[ {g, x, expr}, expr = x^2; g[x_] = expr] You'll notice that this actually evaluates to something (it'll be something like ...
lericr's user avatar
  • 18.4k
1 vote

The way of converting a string to a variable in a loop?

I would suggest two aspects of your code: (1) don't encode information in variable names, as commented above, and (2) don't read everything in a Do loop but rather ...
Roman's user avatar
  • 43.6k
1 vote

Global order setting

The ordering of terms in expressions is not aesthetic but functional. Terms are reordered as part of expression canonicalization. This cannot be changed. You can change how expressions are displayed (...
Szabolcs's user avatar
  • 231k
1 vote

Get the symbol name of the function's nth argument

Based on the answer in the comments, I can create Association that associates arg names to args. Could be useful. (Keys@GetArgs[...][[n]] is the nth arg) ...
user2679290's user avatar

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