Linked Questions

2
votes
3answers
262 views

How can I assign many values each to a different variable? [duplicate]

How can I assign many values each to a different variable? For example, I want to set $a = f(1),\,b = f(2),\,c = f(3),\,\dots,\,z = f(26)$ (generally more variables than these). How can I do this ...
1
vote
2answers
608 views

How to assign values to symbolic arrays [duplicate]

My main question is how to assign values to symbolic arrays, in an efficient way. The code below is a simplified version of what I am trying to do and the output I get. Note that because I am using ...
3
votes
3answers
89 views

Assign Values from Array to Array [duplicate]

I am trying to simply do the following cVec = {a,b,c,d} From another expression, I obtain another vector, say, ...
2
votes
1answer
124 views

Table of references [duplicate]

I have a list of variables (say a, b, c, d, e) that I want to assign in a single command. {a,b,c,d,e} = {1,2,3,4,5} would ...
553
votes
19answers
140k views

Where can I find examples of good Mathematica programming practice?

I consider myself a pretty good Mathematica programmer, but I'm always looking out for ways to either improve my way of doing things in Mathematica, or to see if there's something nifty that I haven't ...
44
votes
5answers
3k views

How to create symbols from strings and set values for them?

I am trying to convert a list of string names into symbols, which will then be used to store data. I have 24 files (where the name of each file is a member of the list mentioned above) that I need to ...
22
votes
5answers
1k views

Reassign values to symbols

I've got a situation where I have, say 4 symbols, a, b, c and ...
52
votes
2answers
2k views

Head and everything except Head?

I have been working on picking expressions apart using Head and Part and encountered a little mystery. Consider the canonical ...
15
votes
3answers
8k views

Assigning values to a list of variable names

As part of a calculation I need to do something like this Evaluate[{aaa, bbb, ccc}[[ index]]] = {1, 2, 3, 4, 5} so if index is ...
10
votes
6answers
1k views

Generate list of strings from a list of assigned variables

How do I generate a list of strings from a list of assigned variables? E.g. convert ...
8
votes
2answers
715 views

How to Clear variables represented as a list of strings?

Say I have a string list called fullpara fullpara={"width", "long", "line", "distance"} And there are corresponding variables ...
2
votes
2answers
1k views

Why this list has a length of 1?

Here is the code : bb = HoldForm[{aa[1], bbb[2], cc[3], dd[4]}] it returns : {aa[1], bbb[2], cc[3], dd[4]} Which is what I ...
4
votes
3answers
434 views

Using Block with a list of variables

I have a list of variables var={v1,v2}; which I want to protect/localize during a particular operation. I have decided that I want to use ...
9
votes
2answers
851 views

How to name a variable with the value of another variable?

A simple but very important (at least for me) question. In some languages for defining a variable, for example, we can do: i=10 "d"&i=30 So I have defined the variable d10, and... d10=30 ...
2
votes
3answers
422 views

How to create a writable and clearable symbol? [duplicate]

I'm trying to create several symbols and assign values to them. Here's what currently appears to work: Evaluate[Symbol["fdds" <> ToString[10]]] = 1 But ...
3
votes
3answers
155 views

Using a variable to tell Mathematica which existing variable to manipulate

I have an estimation routine I have coded up, I want now to do some tests on it where I pick a particular parameter and run the estimation for differing values of that parameter. What I want is to be ...
1
vote
2answers
1k views

Pass the list of variables into function to change their values

I'm new to Mathematica, so I don't really know, how do what I want, and I don't even know how to google it. Doing one Mathematica task for my supervisor, I faced the following problem. I need to ...
4
votes
2answers
247 views

why set values in this way doesn't work?

question is as follows define a list ttt={1,2}; and if I set values in this way {ttt[[1]],ttt[[2]]}={3,4} then the value ...
4
votes
2answers
146 views

Can a Dynamic be attached to the single elements of a list?

Consider the following example: ...
1
vote
2answers
190 views

Why does Evaluate[a[[1]]]=0 assign a value to a variable while a[[1]]=0 doesn't?

I'm trying to do a small page counter with Mathematica, for leting me know about my reading progress on some books. I'm stuck on a problem: ...
1
vote
1answer
398 views

Printing names of indexed variables instead of values

I'd like to display only the variable (indexed variable) name (in symbol form, not in string form) instead of its value in Mathematica. Say I have a variable foo[i] ...
0
votes
2answers
685 views

How to assign the values for the Table list?

Now, I want to assign some values for a Table list and I find that If {mat[1], mat[2], mat[3], mat[4], mat[5]}={4,23,3,12,1}; it is no problem. But, if we use ...
2
votes
2answers
277 views

How to return the unevaluated variable names from a list of variables which have been declared

I feel like this should have a simple answer but I haven't found anything that works. The toy example of what I want is as follows: ...
0
votes
2answers
225 views

How do I use a passed-in symbol as a tag to define UpValues?

ClearAll@foo; foo[tag_] := ( tag /: tag[i_] := tag[[i]] ); a = {7, 8, 9}; foo[a]; a[2] I wanted the above to output 8, ...
1
vote
1answer
251 views

direct assignment to the element in a Table

I have already asked a related question here why set values in this way doesn't work? But I think I have to write the question which I encountered explicitly? ...
3
votes
2answers
138 views

HoldFirst and Hold expression as argument

I store a reference to the association in a held expression in a variable: a=<||>; b=Hold[a]; And in the code, I want to do manipulations with the original ...
0
votes
1answer
216 views

A problem with set values

The following code is just an example to clearly explain my problem. Assume that : ...
3
votes
1answer
116 views

Get the name of a time series while using Table

I saw a number of related questions to the one I'm about to post; they helped, but none of them solved my problem entirely. Get the name of a symbol passed to a function Obtaining the name of a ...
2
votes
1answer
187 views

How to extract a variable names (not values) from a list of transformation rules?

I am trying to extract variable names from a list of transformation rules mapping = {var1 -> 'val1', var2 -> 'val2' }. Variables ...
3
votes
1answer
95 views

HoldFirst being overridden by Activate [duplicate]

So here's the problem a=1;a=2 works because of the HoldFirst attribute of Set, so that it ...
0
votes
1answer
90 views

Set does not work

I tried following code, but it does not work as expected: Do[Set[a[[1]],a[[2]]],{a,{x->2,y->5,z->x+y}}] {x,y,z} I ...
0
votes
1answer
148 views

How to apply Set to held symbols listed in a variable?

I have a variable states that contains a list of held symbols: ...
3
votes
0answers
229 views

I am missing a function like HoldPattern

Temporary message: I am planning to edit this question, making the examples less confusing and by moving the things that are confusing to a separate question For any confusion about expressions that ...
0
votes
1answer
68 views

How to use Set correctly

My codes are shown in the picture attached. I'm writing codes for numerical calculations frequently, and I think it looks neat and clear to organize input parameters in the form of table. For example,...
4
votes
0answers
119 views

How to get Symbol[“x”]=3 to work [duplicate]

This is probably a really simple one, but I'm stumped. I want Symbol["x"]=3 to work just like x=3. However I can't figure out ...
1
vote
1answer
48 views

How to assign a value to an already existing element of a list? [closed]

I want to do the following. Say I have a list: test = List[a,b,c] and I now want to assign some value to elements of that list, so that say if I assign 4 to a, ...
0
votes
0answers
43 views

How to transfer the list of parameters values into With [duplicate]

In the following case: With[{x=1,y=2},Print[x+y]] the values of x and y are declared in ...
1
vote
0answers
29 views

Assign to variables inside Array, rather than changing array entries [duplicate]

I am generating an Array with symbolic coefficients: coefficients = Array[c, 3] > {c[1], c[2], c[3]} I would like to assign a value to each of these generated ...