Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [assignment]

For questions relating to assignments to symbols, patterns, or expressions.

1
vote
2answers
30 views

A question about a replacement of element of set

To begin with, I'm a poor English speaker, which means it would be hard to read to natives... I was trying to memorize mRNA codons with mathematica. ...
1
vote
1answer
63 views

How to use an up-value assignment when all symbols are “too deep”?

I would like to make an up-value assignment such as a/:Conjugate[a[x]]a[x]+Conjugate[b[x]]b[x] = 1 or ...
0
votes
1answer
51 views

Replace constant in summation function using replace or If or /

Hi i how do i replace constant for k in this summation. For following: Even 2*n Even replace k by a Even 2*n+1 Odd replace k by b Here is the code ...
1
vote
0answers
54 views

Making a function definition where the right hand side is evaluated before the definition is saved [closed]

My question is about assigning the resulting expression after evaluation of a function. So what I want: FOCf[x, y] := D[f[x, y], x] such it immediately ...
3
votes
2answers
103 views

Is it possible to set values for a list of variables using a for loop? [duplicate]

Let me preface this question by noting that this is a simple example meant to clarify what I am asking. The actual context in which I want to implement this involves associations containing hundreds ...
4
votes
2answers
114 views

Scoping of pattern variables [duplicate]

I have run into a problematic behavior, and then came to find that it is a "possible issue" called out in the documentation, but I guess I am just baffled that this IS an issue, and am wondering why. ...
-1
votes
1answer
54 views

Why it is doing part assignment? [closed]

I am writing an algorithm and need to keep updating an association called "verticesAssoc". My algorithm ran perfectly at first. However now I want to use the same algorithm on another association "...
0
votes
0answers
20 views

Seeing definitions of built-in functions [duplicate]

Possibly a very amateur question, so I'll apologise in advance. I'm reasonably new. I'm trying to write a Dot equivalent of ...
6
votes
1answer
64 views

unexpected result from augmented assignment to association

Is the last of these results expected? If so, how? ...
3
votes
2answers
175 views

Transferring DownValues

I have a code in which I define something like this: cc[1, 2] = 1; cc[2, 6] = 12; cc[3, 7] = 3; After some manipulation I define a sort of temporary variable ...
0
votes
0answers
41 views

Reassignment of variables

Another quick question of mine. If I want to assign variables to be some arrays in parallel, I can use a construct like ...
2
votes
1answer
67 views

Reassign a value to an array element

I have a very complex code in which I assign a value to an element of an array and then I reassign to it another one. A minimal example: ...
1
vote
1answer
63 views

Evaluating the 1st argument of Set

I want to assign a certain value to an element of a tensor. This element is identified by an array obtained from some evaluations, so we fix it. Here i present an oversimplified core part of my code: ...
1
vote
1answer
287 views

Tag Times in Null is Protected [closed]

I've some problems with the error mentioned in the title. Unfortunately, my code is full of subscripts so I'll show it in a photo. In this code the central aspect is to assign a scalar value to an ...
1
vote
3answers
131 views

Assign a function within a function [duplicate]

What I'm doing wrong? 1st function works as expected but the 2nd one doesn't. What I want is to enter an algebraic expression and two numeric constants and get the same result as with the first ...
1
vote
1answer
43 views

How to use a calculated expression on left-hand-side of an assignment?

Elementary question, I guess: I have a left-hand-side something like this: ...
0
votes
0answers
51 views

Trouble with UpSet(Delayed) and IgnoringInactive

I'm having problems setting an upvalue for a symbol that is supposed to ignore Inactive: IgnoringInactive[f[g[x]]] ^:= match; ...
0
votes
2answers
44 views

Hot to single out numeric values from NMaximize

I have some problem with NMaximize. The function NMaximize gives result like this NMaximize[f[x],x] {f[xmax] ,{x -> xmax}} I've read in various answers that ...
3
votes
1answer
80 views

assignments within Manipulate

I have encountered unexpected behaviour when assigning variables in Manipulate. Consider an inverted parabola y[x_, c_] := -x^2 + c The following code finds the ...
0
votes
1answer
57 views

Symbolic variable assignment

I looked around and didn't see this question on the forum, so my apologies in advance in case this has been answered here. My question can be concisely described by the following example: ...
1
vote
2answers
89 views

How to assign values using nested Part[ ] expressions?

Why doesn't this work? Can I make it work? ...
0
votes
2answers
82 views

How to 'unassign' variables used for PlotPoints, which subsequently print as e.g. Charting`Private`pvar$727158

I have a table of four insoluble equations, fceq, in terms of unassigned variables, Subscript[fc, i], Subscript[μ, i]. I am using contour plots to visualise ...
11
votes
2answers
1k views

Can't understand one paragraph in Power Programming with Mathematica

In the chapter 7 of the Power Programming with Mathematica, there is a paragraph discussing the behavior of Set- functions: (page 205. (pdf version p. 224)) ...
0
votes
1answer
32 views

Assigning eigenkets to particular eigenspace depending on eigenvalues of system inside a module

I am writing a module, in which the Observable and State is given, so I need to write a function/module QuantumMeasurement, that will return a state of the quantum system resulting from the ...
0
votes
0answers
37 views

assigning numerical values to variable

I have a csv data file, has two columns of data. First column denotes time (t) and the corresponding value in the second column is flow rate (f). I would like to assign these values to an array f[t], ...
1
vote
2answers
54 views

Assigning variables whilst in a context

When working in a context, I would like all variable assignments to happen on symbols in the new context. This doesn't normally happen. For example, ...
5
votes
2answers
142 views

How to set parts of Associations “named with” SubValues

Parts of Associations can be set with the following syntax: as = <|"a" -> 10|> <|"a" -> 10|> as["b"] = 20; as ...
2
votes
0answers
54 views

Writing a variable to file with its value, not its name [closed]

This is my first time ever posting a question about Mathematica anywhere, so please excuse my ignorance. I'm trying to save a ColorFunction to file, but can't get the variables to be written as ...
2
votes
1answer
112 views

Generalization of the probability of union

hi How can I do for mathematics to expand this equation for any value of the variables i, j, k
3
votes
0answers
417 views

Multiple variable assignment from a list

For example in Python, if we have a list of 3 elements, say ls = [1,2,3] and we want to assign a variable to each value (from left to right), one can do as follows: ...
2
votes
0answers
63 views

Matrix as function manipulation

Consider matrix mat[x_] := {{1, 2}, {3, x}} with mat[x][[1]] giving {1, 2} I wanna ...
11
votes
2answers
2k views

How to pass variables by reference and by value [duplicate]

I haven't seen this question specifically addressed before in this site, although some hints and traces have been given, for instance, here: Pass by reference for an option argument Does pass-by-...
5
votes
1answer
67 views

Set on symbol with OwnValues skips UpValues

Can anyone provide insight on what's going on here? First I define a new Set behavior for a symbol: ...
2
votes
0answers
90 views

How do I assign a value to a[1,2][[3]]?

How do I assign a value, say 7 or "t", to a[1, 2][[3]]? a[1, 2][[3]] = 7 and ...
2
votes
1answer
25 views

Refer to solution from matrix [duplicate]

Consider matrix equation m = {{1, 2}, {3, 4}} l = {{1}, {0}} p = {{p1}, {p2}} eq = m.p == l Solve[eq] Output is {{p1 -> -2, p2 -> 3/2}} But p1 and p2 do not ...
8
votes
2answers
198 views

Confusion about HoldFirst attribute of Set

Set has the attribute HoldFirst. Expectedly the following does not work, i.e. it does not assign the OwnValue of 3 to x: ...
9
votes
1answer
343 views

Part not behaving the way I expect it to

p = {{1, 0, 0}, {0, 1, 0}, {0, 1, 0}}; p[[All, 3]][[1 ;; 2]] = {1, 1}; p I want to replace the first two elements of the third column of a 3x3 identity matrix. ...
4
votes
2answers
216 views

Wrongly assigning a value to an expression

Sometimes I misstype an equality and I write an assignment instead. For example, if I write f'[x] = 2 instead of an equation, ...
3
votes
2answers
109 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 ...
3
votes
0answers
47 views

Variable assignment/replacement issues

I have three questions about variable assignment. Module[{z}, z = y; p'[y] /. p -> Function[y, Evaluate[z]]] When I run the above code, it outputs 0. 1) If I ...
4
votes
1answer
105 views

Assignment via iteration over list of variables to be assigned values

Variations on my question have been asked before (How to re-assign values to a List of variables?, How to use Table to assign values to variables in a list?, Assigning values to a list of variable ...
4
votes
2answers
84 views

Combining SetDelayed, Set and Options [duplicate]

A function can be defined with SetDelayed while storing its value with Set, eg: ...
5
votes
2answers
68 views

Vectorized AssociateTo

With an Association we can update keys in place two ways: ...
0
votes
1answer
44 views

Create a list of indexed matrices and then change their entries

I make a list of 5 empty $3 \times 3$ matrices via Table[m[i]=IdentityMatrix[3]-IdentityMatrix[3],{i,1,5}] However when I want to change an entry via ...
3
votes
2answers
211 views

assign 2 letters in a subscript

Suppose I want to solve an equation for the matrix elements of $\bar{W}$: $$\alpha W_{ba}+\beta W_{bb}=x; \alpha W_{aa}+\beta W_{ab}=y$$ Using the syntax ...
7
votes
2answers
219 views

Apply ToString to a list of variables [duplicate]

I have data1 = {1, 1}; data2 = {2, 2}; datalist = {data1, data2}; I want to create a string list based on the variable names inside ...
11
votes
2answers
446 views

Is there a convention on which name to use for a throwaway variable? (Like underscore in Python) [duplicate]

I would prefer to write {_, foo} = LongFunctionName[arg1, arg2] instead of foo = LongFunctionName[arg1, arg2][[2]] or ...
2
votes
1answer
182 views

Define a function to be equal to the numerical solution of a PDE [duplicate]

I am curious about if it is possible to define a function to be equal to the numerical solution of a PDE (got by NDSolve)? I know that when we try to plot the ...
4
votes
2answers
78 views

Define function of a list from a function of its elements (Set)

I asked a similar question there: Define function of a list from a function of its elements (SetDelayed). This one is different because I'd like to use Set instead ...
2
votes
1answer
99 views

Switch in functions and their derivatives

Consider the following simple example: ...