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})
...
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 ...
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
...
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 *)
5
votes
Accepted
How to directly define a function as the solution of RSolve
To make my comment clear, here is the full code:
...
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, ...
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 ...
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-...
4
votes
Can you use superscripts as variable and function names?
ClearAll["Global`*"]
Format indexed variables
...
4
votes
Repeating definitons of variables
Following Syed's idea, another way to do this is to use FoldList:
...
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.
...
3
votes
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 ...
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))
...
3
votes
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 ...
3
votes
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
...
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]
...
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]
...
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 ...
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}]
...
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 ...
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.
...
Community wiki
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
...
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.
...
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 ...
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 ...
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 (...
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)
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
variable-definitions × 495functions × 75
function-construction × 62
variable × 51
scoping × 36
list-manipulation × 34
evaluation × 31
equation-solving × 25
assignment × 23
plotting × 21
symbols × 21
matrix × 19
replacement × 16
syntax × 15
programming × 14
manipulate × 12
symbolic × 12
core-language × 12
differential-equations × 10
pattern-matching × 10
warning-messages × 10
complex × 10
packages × 10
clear × 10
calculus-and-analysis × 9