Tag Info

Hot answers tagged variable-definitions

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}) ...
• 54.2k
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 ...
• 32.2k
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 ...
• 130k

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,699
Accepted

How to directly define a function as the solution of RSolve

To make my comment clear, here is the full code: ...
• 40.7k

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, ...
• 32.3k
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 ...
• 32.3k
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-...
• 43.6k

Can you use superscripts as variable and function names?

ClearAll["Global*"] Format indexed variables ...
• 144k

Repeating definitons of variables

Following Syed's idea, another way to do this is to use FoldList: ...
• 9,129

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. ...
• 18.4k

...
• 5,935
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 ...
• 11.7k

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)) ...
• 67.5k

Repeating definitons of variables

x = 2; n = 2; The general solution is ...
• 144k
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 ...
• 57.7k

How can I make 10 variables from a for loop?

You could use ToExpression ...
• 130k
Accepted

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

Method 1. One could use ...
• 11.7k
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] ...
• 130k
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] ...
• 130k

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 ...
• 127k

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}] ...
• 35.6k

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 ...
• 229k

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

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 ...
• 35.6k
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. ...
• 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 ...
• 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 ...
• 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 (...
• 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) ...
• 185

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