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

learn more… | top users | synonyms

4
votes
4answers
255 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 ...
0
votes
0answers
34 views

Assignment problem in Mathematica [duplicate]

Doing work ... v := {v1, v2} := {1, 2} ... I get that v is a vector of length two (and this is enough for me), but unfortunately in v1 and v2 are not assigned 1 and ...
6
votes
2answers
95 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 ...
4
votes
3answers
194 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 ...
5
votes
3answers
170 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 ...
1
vote
3answers
113 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., ...
7
votes
2answers
164 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 ...
27
votes
3answers
422 views

Assign a randomly generated list to variable

Bug introduced in 10.0.0 and fixed in 10.0.2 I don't know if this is a silly question, but it really baffles me. So please help me understand this behavior. ...
8
votes
2answers
297 views

How to replace a variable that was assigned a value before

Question How to make the replacement $f[x] \to f[y]$ for an abitrary function $f$ if $x$ was assigned a value before? Example 1 How can I make the replacement $x +1 \to y + 1$ if I have assigned ...
0
votes
1answer
89 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] ...
4
votes
2answers
118 views

Initializing several values of a function

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

How to augment the realm of functions Mathematica thinks it knows how to integrate symbolically

My question involves extending the functionality of Integrate over specific integrals in the most generic manner. Specifically, is it possible to "hack into" ...
2
votes
1answer
105 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 ...
8
votes
3answers
3k 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 ...
26
votes
1answer
838 views

How do you set attributes on SubValues?

SubValues, as discussed in a previous question, are declared as follows ...
8
votes
3answers
341 views

How to write a function-defining function which stores the function arguments in a stack?

I have a function-defining function SetAttributes[DefFn, HoldAll]; DefFn[f_[args___], body_] := f[args] := body; I am trying to modify this function to record ...
19
votes
5answers
17k views

Assign the results from a Solve to variable(s)

I understand Mathematica can't assign the results of a Solve to the unknowns because there may be more than 1 solution. How can I assign the 4 values of following result to variables?
3
votes
2answers
118 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: ...
22
votes
1answer
472 views

Why does list assignment with a packed array result in unpacked values?

Bug introduced in 5.2 or earlier and fixed in 10.1.0 This is another question on the design choices in Mathematica. I understand that without direct reply from the developers it may not be ...
8
votes
1answer
116 views

Maximum number of literal values for SetDelayed?

Under what circumstances should I expect Mathematica to turn a delayed assignment into an immediate assignment? I have put together a minimal example (available here) which demonstrates this behavior. ...
2
votes
1answer
190 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 ...
3
votes
0answers
38 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 ...
1
vote
1answer
72 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 ...
1
vote
0answers
24 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 ...
3
votes
0answers
93 views

Why is it not allowed to define vectors of variables in a scoping construct?

The following command assigns 1 to a, 2 to b and 3 to c: ...
0
votes
2answers
38 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 ...
5
votes
4answers
541 views

Delayed evaluation of assignment

I have a set of PDE's that depend on parameters. They depend on many parameters, but for simplicity we can here assume that they depend only on one, say a. I want ...
1
vote
1answer
80 views

Simultaneous use of Set AND SetDelayed

Tha Mathematica documentation gives a good example of the simultaneous use of Set and SetDelayed in dynamic programming for the Fibonacci sequence under "neat examples" for SetDelayed ...
0
votes
1answer
52 views

Refercing generic derivatives

I have a list of rules to the values of the derivatives of a generic (real valued, 3 variables) function, for example: df/dxdydz(0,0,0)-> 0.7. I would like to be able to generically reference this ...
17
votes
2answers
503 views

Does Set vs. SetDelayed have any effect after the definition was done?

I was always assuming that the only difference between Set (=) and SetDelayed (...
4
votes
3answers
191 views

Altering values in Manipulate with dynamically generated controls

I have a Manipulate whose controls are generated based on a parameter in a containing Manipulate: ...
1
vote
2answers
73 views

Assigning to the “local” version of a symbol

Compare Manipulate[c[1] = 1; c[1], {c[1], 0, 1}] with Manipulate[Do[c[i] = 1, {i, 1}]; c[1], {c[1], 0, 1}] The first case ...
9
votes
2answers
126 views

DownValue assignment using Apply

Why does assigning a DownValue using Apply, e.g., ...
5
votes
4answers
379 views

Is there any way to assign multiple values?

I am looking for something like "byref" assignment in programming languages. Let's assume I have: x1=x2=....=xn if I want to change their values ( say to 3 ) I need to set all of them like: ...
5
votes
3answers
387 views

Assign output of solve to variables [duplicate]

I have this input: Solve[x^2 + 3 x + 2 == 0, x] which gives this output: {{x -> -2}, {x -> -1}} I want the first x ...
-2
votes
1answer
133 views

Trouble to assign solution of differential equation to a function

I have written a function to Solve the following differential equation where the number n (called in my code Nphoton) is a variable. Nevertheless I have troubles to assign the solutions ...
1
vote
0answers
48 views

How do I assign a formula to a variab [duplicate]

I want to compute equations and assign them to variable. This is a wxMaxima program that calculated symbolic PID gains for an integrating first order system ...
3
votes
0answers
63 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 ...
5
votes
1answer
91 views

Edit built in symbol

I would like to add new attributes to built in symbols (e.g. ElementData or PolyhedraData) so that I can still call the symbol ...
20
votes
3answers
411 views
0
votes
0answers
51 views
17
votes
4answers
317 views

Setting parts of a list

Suppose I have list a = Range[10] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} in which I want to set some elements to be a list ...
17
votes
4answers
1k views

How to implement the Observer design pattern?

As a programmer with a history with procedural languages, the Observer design pattern inmediately springs to my mind when attacking certain class of problems, mostly UI/notifications related. A ...
3
votes
2answers
451 views

How to copy a function by value?

I need to change a function symbol multiple times by assigning another symbol to it, but when I'm trying to do that the symbols overwrite each other. I'm assuming this is because the assignment is by ...
0
votes
3answers
109 views

Evaluating an expression assuming a value for a variable only in the local context

Imagine we wish to evaluate some expression like NIntegrate[x^2*q,{x,0,100}] assuming some value for q like ...
0
votes
1answer
63 views

Questions regarding DictionaryLookup of Mathematica

a. Make a function longest[lang_] that gives the length of the longest word in the dictionary of lang. You should get ...
1
vote
2answers
135 views

Few quick Mathematica questions about Dictionary

a. Get the list whose elements are of the form {language,number of words in dictionary) I tried this, and it gave me the number if words in dictionary, but I don't know how to get the language part: ...
1
vote
1answer
36 views

How to assign a list of subsript?

I want to assign Subscript[C,i] by mapping a specific list. For example, the list is {1,2,3,4}, and I want to assign 1 to C1, 2 to C2, 3 to C3 and 4 to C4. How should I do? Many thanks:)
3
votes
2answers
152 views

Bare symbol invocation fails but not if used with an argument

How to achieve the following behavior on a symbol f? Background: The main goal is to use the symbol to tag an abstract data structure where downvalues are used to store information. Only defined ...