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

learn more… | top users | synonyms

3
votes
2answers
177 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
60 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
43 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 ...
0
votes
0answers
28 views

Questions about CountryData

a. What is the proportion of Internet users to population in the United States? I am really confused. I don't where to get these information from and how to set up the proportion. b. What countries ...
1
vote
2answers
91 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: ...
0
votes
1answer
29 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
123 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 ...
0
votes
1answer
65 views

Circumventing the default scoping: Assign a variable inside a function [duplicate]

I'm currently trying very hard to assign a variable inside a function. Therefore I'm using a function like this, which should reassign a predefined variable. ...
3
votes
1answer
53 views

Replacing multiple instances of a symbol with different variables and assignments

I have an expression of the form: expr=x+y+n+Sin[n]+n^2 I would like to replace each of the variables n with a different ...
0
votes
2answers
89 views

Associate the elements of a table

I have a table form as: table = {{a, 6}, {b, ff}, {c, 2}} I want to associate the first element of each pair from the table to the second element of the pair as ...
1
vote
1answer
47 views

storing rescaled images in new variables

I'm trying to assign random image files that undergo rescaling to a list of variable names. The images I'm trying to assign are the result of mapping the ImageResize function of two arguments to the ...
1
vote
1answer
112 views
6
votes
3answers
181 views

Understanding Function and Variable in Mathematica for beginner [closed]

I'm reading the book of Leonid Shifrin, and I love the way the book explains the core in Mathematica. As everything is an expression, now I understand that, there ...
3
votes
3answers
98 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 ...
0
votes
0answers
99 views

Assign variable's value programmatically

Not easy to explain what I'm looking for, so please sorry if I'm not so short. Having many variables to be managed in several different combinations, I need to automate the assignment of preset ...
2
votes
1answer
123 views

Assign one button to two variables

I am trying to use the one button to assign to two variables. Here is an example of how I want it to work. expression: ...
3
votes
1answer
234 views

Integral of Lorentzian yields different results depending on when parameter assigments are made

I'm evaluating the integral of a Lorentzian, which I know equals one. First I define the function and evaluate the integral in two slightly different ways. Surprisingly, I do not get the right answer ...
0
votes
1answer
95 views

Getting mesage: Set::setps assignment is not a symbol

Please, tell me what is the issue with the following code? Dimensions[Subscript[R, 2]] {201, 161, 53} ...
1
vote
1answer
98 views

Two quick Mathematica Questions about the dictionary

Question1: Get the list of pairs of the form {language,number of words in dictionary}. Call this list langlength What I did was this: ...
17
votes
3answers
311 views

Nested definition: How can I define a function with a passed-in expression?

Here's a simplified version of what I'm trying to do: ...
6
votes
2answers
227 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 ...
20
votes
1answer
512 views

How do you set attributes on SubValues?

SubValues, as discussed in a previous question, are declared as follows ...
7
votes
2answers
137 views

How to ignore list elements when extracting with pattern matching

If I have a simple list, say {1, 2, 3}, and I want to extract a subset of the elements, what is the correct syntax? e.g. { i, _, j } = {1, 2, 3} I want i = 1 ...
19
votes
0answers
228 views

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

This is another question on the design choices in Mathematica. I understand that without direct reply from the developers it may not be possible to give a definitive and exhaustive answer to "why" ...
0
votes
0answers
141 views

Assigning numerical values to constants results in complex coefficients in Equations of Motion

I am using Mathematica to get the Equations of Motion (EOM) for a mechanical system (using Lagrangian Mechanics). While I get the EOM in symbolic form, on introducing the following code for assigning ...
0
votes
1answer
57 views

Extracting function variables from a list [duplicate]

Evaluating the following func[x_, y_] := x^2 + y^2 listn = {{a, b}, {c, d}, {e, f}}; Map[func[##] &, listn, {1}] yields {func[{a, b}], func[{c, d}], ...
4
votes
2answers
106 views

Choosing an initializer list in With

I'm trying to have several initializer lists in a With function and choose which one I want to use. So far I have this: ...
19
votes
5answers
454 views

Reassign values to symbols

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

How to pass a symbol name to a function with any of the Hold attributes?

Given a function with the attribute HoldFirst, HoldAll or similar, and a variable, list, how ...
5
votes
1answer
155 views

Assign variables automatically to a function

Lets consider that I've this function: fn = a*x^2 + b*x + c; The idea here is to assign automatically the variables a, ...
8
votes
1answer
146 views

Different behaviours of Default Argument

I don't really understand the behaviour of Default Argument. If I execute this command in Mathematica: In: {f[a], f[a + b]} /. f[x_ + y_.] -> p[x, y] ...
0
votes
0answers
23 views

How to assign values to a function at discrete points? [duplicate]

Suppose we are interested in a function f[x] that is defined only at discrete points: x = {1.1, 2.1, 3.1, 4.1, 5.1} We want to ...
1
vote
1answer
126 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? ...
4
votes
2answers
172 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 ...
1
vote
1answer
105 views

How to work with Interpolated Functions? [closed]

I am just a beginner and struggeling with experimental data and further processing in Mathematica: I first constructed a table from two columns (t20 and J20) in Excel: ...
11
votes
2answers
279 views

Triggering actions when a variable is set

Some built-in variables trigger actions when their values are changed: ...
3
votes
3answers
103 views

Can I put subscripted parameter values into a package?

When defining packages, can I put parameter values alone or along with functions into a package in subscripted form? ...
1
vote
1answer
100 views

Using With in combination with Graphics [duplicate]

Assume that we are given a symbol p={x,y} which should represent a 2D point. If x and y have ...
14
votes
3answers
6k 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
1answer
86 views

Syntax Coloring for “Possible Unwanted Assignment” Issue

Apparently Mathematica's syntax coloring engine believes that the second assignment in the following code excerpt (concocted for illustration purposes only) is a "Possible Unwanted Assignment" since ...
10
votes
3answers
303 views

Why does ++++x return an increment of 2 when the value of x is only incremented by 1?

This line returns 3: x = 1; ++++x However, the value of x after the increment is only ...
1
vote
2answers
133 views

How to mix Unevaluated property of function arguments with expression assignments?

This is a follow-up to my (solved) question How to distribute a generic function of two arguments (without evaluating the arguments) Say, I have a binary function ...
22
votes
1answer
473 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" ...
13
votes
2answers
269 views

How to make use of NumericQ[x] = True (and use it safely)?

Basic Issue: I'm trying to understand the proper use of NumericQ's "magical" capabilities. Please consider the examples below. Actual question and some links are ...
4
votes
2answers
447 views

How to store value in a For loop

I am using two For loops. When the inner loop finishes, I don't want to print but I want to store the result from the inner loop in some variable so that I can call ...
7
votes
1answer
164 views
10
votes
2answers
392 views

Scoping in assigning a derivative

While answering another question, I stumbled upon a problem I cannot easily resolve. To assign the derivative of a function to another function, typically one can do this with a ...
3
votes
1answer
134 views

Set promotes Rule to RuleDelayed?

In mentally building a model of how Mathematica works, I naively expected Set to create a Rule in a symbol's ...
6
votes
3answers
1k 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 ...
13
votes
1answer
266 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 (...