# Questions tagged [assignment]

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

232 questions
Filter by
Sorted by
Tagged with
77 views

### Using HoldFirst at the same time as Apply

I have some code which pops the first number from a list, displays that number, and updates the list: ...
246 views

### What's wrong with the Sum function?

Here are the codes: ...
223 views

### Evaluating ReplaceAll inside SetDelayed, first

Consider the following (simplified for the purpose of example) definitions: f[x_] := y /. y -> x g[x_] := x Where for example, the definition of ...
107 views

### Different Plot's output defining a function

I want a plot with this function -((H^3 T)/(200 Pi)) + (H^2 T^2)/96 + H^4 l + H^2 m with ...
47 views

### Solving for a function after replacing and substituting in an expression [duplicate]

I am trying to isolate $X(s)$ in the following expression: ...
200 views

### How can I assign a value to a multivariable function in Mathematica corresponding to only one of the variables? [closed]

If I consider a function for example: g[x_]:=x^2 and fix g[x0]=10.0 at a certain point x0, ...
125 views

### How to set a symbol indirectly?

I have a symbol, say x, whose calculated value is a 2nd symbol. How can I set the 2nd symbol to a given value? For example, say the value of x is one of the symbols a, b, or c. If it is a, I want to ...
113 views

### Use Table to set Imported Variable? [closed]

I'd like to assign a SemanticImport dataset to a variable on import. Right now, I have this, and it doesn't work: ...
255 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 ...
66 views

### Assigining values after the Apply operator

I am writing a script where I need many variables and for ease of usage I denote them as f[k,l,m,n]. I create a list of 4-tuples with the integers I need and I call ...
147 views

### Programmatically assign output Hold[…] produced by errors to a variable

expr = Return[1, 2] Return::nofunc: Function 2 not found enclosing Return[1,2]. >> (*Hold[Return[1, 2]]*) However, ...
87 views

### Why does syntax highlighting in Set and Rule not color pattern names on the RHS?

The mathematica front-end colors x on the right hand side of x_ :> x and f[x_] := x but ...
86 views

### Part function: can we use pattern for part functions? [duplicate]

Can we use some patterns for the arguments of Part functions? ...
157 views

### Association matching still not working perfectly?

Bug introduced in 10.4 and persisting through 11.1.1 Up until 10.4 you could not match on internal Association structure at all: https://mathematica.stackexchange....
146 views

### How to create assignments to OverVector programmatically

I wish to write a function that accepts two lists. The 1st argument is a list of lists, holding the components of a several vectors. Ex.: comp = {{a, b}, {c, d}}. ...
854 views

### Can you unpack a list of values into variables in a With expression?

For instance, if I am trying to draw a graph with 5 vertices labeled a through e, and I want to draw edges connecting a and b, a and c, a and d, a and e, b and c, b and d, and c and e, I would run the ...
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,...
148 views

### Using delayed evaluation on module variables called through an association

I came up with a construct that works well enough for my current use case but has some flaws (at least I suspect it does). Say we have a function that calculates some stuff that takes a while to ...
137 views

336 views

### Why is the first argument of the SetDelayed evaluated?

In: f=g; In: SetDelayed[f[x_],x^2]; In: ?f Globalf f=g In: ?g Globalg g[x_]:=x^2 However, SetDelayed has the ...
529 views

### Looping through 3 million elements of a list to 'Set' values is slow

I am looping through the 3 million elements of a time-series (v1, o1) and corresponding values (v2, o2). v1 contains a uniformly increasing timestamp (e.g. 1 to 3,000,000 in increments of 1) o1 ...
127 views

### Table generation with SetDelayed function [closed]

I would like to understand why the following two outputs differ: Let us define the following data set: ...
263 views

### Force evaluation of the right-hand side of a local variable definition

One can do expression = a + 1; f[a_] := Evaluate[expression] but how would one do something like this ...
312 views

### Correct definition of a function to be passed to Nintegrate [duplicate]

If I type the following code ...
603 views

### Turning an expression into a function inside another function

Say I have an expression g=Sin[q]; It is easy to turn it into a function, and to perform manipulations on this function (this and variants of this were discussed ...
174 views

### Setting ::usage for variables returned from a function

What is the best way to achieve {v,u} = f[]; (* Returns value and usage description *) v::usage = u; from inside f, i.e., <...
317 views

### Passing an unevaluated part of an association to a function

I'm making a UI widget that controls sound volume on a speaker using a slider, e.g.: ...
380 views

### Variable dependency…easy one

I'm brand new to Mathematica...should be an easy one. Instead of writing u[x] everywhere in the code, how do I assign the dependency early on like this: u=u[x] ...
135 views

### Initializing several values of a function

How do I initialize several values of a function at once? Consider the function f := 1; f := 2; f := 3; f[n_] := f[n] = f[n-1] + f[n-2] + f[n-3]; Is ...
663 views

### Assignments in ParallelDo when using indexed variables

For convenience I use an indexed variables syntax to hold results of long computations for different integer parameters: ...
950 views

### How is LHS = RHS; … ; LHS (nontrivially) different from … ; RHS

I'm trying to understand how Mathematica thinks about the results of Set. Suppose we perform LHS = RHS. I'm focusing on when ...
41 views

### Out[x] not the same as assigned expression [duplicate]

There seems to be a difference in the way Mathematica assigns a value to a variable and the way it assigns a value to the next Out object. I don't understand why this is happening. For instance, take ...
870 views

### Is there a way to simplify a symbolic expression at assignment, once-for-all?

I have a series of symbolic function calls that could be greatly simplified using some assumptions. I think I would like for these assumptions to be used in the definition of the function so that they ...
151 views

### Is it possible to assign a value where the target is itself a variable

If I have a variable x := "a". Is there a way I can use it to assign a value to a, by just referring to ...
205 views

### Problem with Simplify, Sqrt, and Set: What's going on?

I am having some trouble getting Mathematica to simplify an expression of the form Sqrt[x]*Sqrt[1/x], where x>0. The problem ...
425 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 ...
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, c, c} I would like to assign a value to each of these generated ...
644 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, mat, mat, mat, mat}={4,23,3,12,1}; it is no problem. But, if we use ...