Tagged Questions

Questions on assigning and unassigning definitions to names that represent them, including issues raised by context and localization. Use tag [assignment] for issues relating to Set versus SetDelayed.

learn more… | top users | synonyms

0
votes
1answer
22 views

How to tell Mathematica that certain variables are real/imaginary, integer-valued, etc

I'm trying to expedite some quantum mechanical calculations by running them through Mathematica. Expectation values and stuff like that. When I say, for example, ...
0
votes
1answer
24 views

Variable as Difference of 2 Variables

I would like to evaluate a function based on the absolute difference of two variables. An example: g=5*x-5*x*y-5*y diff=x-y D[g,x] D[g,y] D[g,diff] I cannot find ...
3
votes
1answer
45 views

Defining a function that prints both the name and value of a variable defined locally within the calling function

To save time when debugging with Print statements, I'd like to define a function -- call it PrintVal -- that prints both the name and value of a variable defined locally within the calling function. ...
1
vote
1answer
72 views

How to form a variable from matrix elements

I have matrix with n rows and 2 columns, say m = {{x11, y12}, {x21, y22}, ..., {xn1, yn2}. Now, I want to form three new variables for example: ...
1
vote
0answers
90 views

How to create a complex variable from dated list values

Can anyone help me to construct a variable "PI" from values of variable x. Variable x represents a group of two time series rj and ri on equal dates(joined two dated lists with states).Variable x have ...
2
votes
1answer
61 views

Equivalent command to the Maple indets command

This carries on the discussion here and here. I had mistaken Variable[] to give you ALL variables in an expression, but apparently, it is not meant for that. ...
0
votes
1answer
71 views

About Symbolize and Variables

I do believe this sort of similar questions had been asked many times, so I have read a LOT. For example this and this as well as many other related posts. But a glance at what my main question is ...
3
votes
1answer
70 views

Need some explanation of “Global`*”

When I start a new notebook, I enter Names["Global`*"] I get this {"list", "msgs", "rhs", "z"} Then I enter, ...
0
votes
0answers
14 views

SharedVariable in WebMathematica

How can I create a variable to be used and setted over all my WebMathematica kernels? Here is the case: Create a package with do data structure like: data = ...
0
votes
2answers
110 views

Variable Value as Range

Thank you for the help so far! I would like to assign +/i signs for the function and solution such as (+)(+)(-) and therefore (-). It is working for the first evaluation, ╬╗lower, but not for the ...
3
votes
2answers
124 views

Convert matrix rows into variables

Can anyone show me how to set all matrix rows to variables. For example, I have matrix w={{1,2,3},{3,2,1},{0,0,0}} and I need to set each matrix row to be separate ...
0
votes
0answers
39 views

Replacing variable names in a notebook

I am working on a code that simply imports and graphs a function. If I preset the directory I would have something that looks like this: ...
5
votes
3answers
127 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 ...
13
votes
1answer
285 views

Is garbage collection broken in version 10.0.0?

Bug introduced in 10.0.0 and fixed in 10.0.1 In version 10.0.0 under Windows I am observing the following behavior: ...
2
votes
2answers
90 views

Local variables whose definitions depend on each other [duplicate]

Consider the following (pseudo-)function definition: f[l_] := Let[{ a = Length[l], b = First[l], c = b/a, }, c*10] So for ...
1
vote
3answers
74 views

Store matched variables

Edit: I am matching and replacing a particular expression. At the same time... I want to store matched variables for later use. I got it to work with messed up code involving ...
1
vote
1answer
92 views

Solving equations with QuantityVariable

I'm trying to understand how to easily solve equations that use QuantityVariable. Why does this fail? ...
0
votes
1answer
31 views

Why would this function work only when I make a copy of the variable? [duplicate]

Why would this function work with a copy of the function variable: ...
6
votes
2answers
101 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 ...
0
votes
1answer
36 views

Reducing Output length by introducing new variables [duplicate]

I have outputs like "expression/(1+3*c^2) +anotherexpression/(1+3*c^2)" and so on. Is there any way to set 1/(1+3*c^2)=A where A is a new variable so that the output reads like ...
1
vote
0answers
60 views

specifying a list (vector) of arbitrary length

When trying to do symbolic calculations in mathematica involving a space of dimension n, which is arbitrary but fixed, I'd often like to work with vectors that have ...
4
votes
1answer
76 views

How do I constrain variables to a user-defined domain in ArgMax?

I am trying to ArgMax a function over x, but x is only defined between ...
26
votes
2answers
1k views

Best practice of passing a large number of parameters to functions

I have a number of functions that all take a large number of parameters. I am wondering what is the best practice of passing these parameters to those functions. I could, of course, simply specify ...
0
votes
1answer
56 views

Is there a command returning information about a particular object? [closed]

Suppose I have a variable var1, a function MyFunction, and a graphic SomePlot. I remember ...
4
votes
1answer
121 views

Multiple down-values with exactly the same lefthand side

I was working on an answer to this question, when I was sidetracked by what I bring up here. I wanted a function, which when given a string representing a binary number, would convert the string to a ...
0
votes
0answers
49 views

Coupled ODEs with boundary conditions - DSolve Error

I'm relatively new to mathematica and I can't find the error here. I suspect it has something to do with the fact that vx, vy, vz aren't blue on my mathematica - as in, they already have some assigned ...
1
vote
2answers
88 views

Using AddTo in a function

I want to create a function that will take a variable $x$ and reassign the value $x+2$ to $x$. So f[x_]:= x += 2 However: ...
0
votes
3answers
105 views

Identifying the symbol which has a specific value

I'm writing a program that will solve the value of 1 variable in a 4-variable equality equation, but the variable to be solved will depend on the user's input to the program. This is what I've come ...
1
vote
2answers
72 views

Calling variables with use of numbers in their names

I have got few huge matrices named by ascending numbers, e.g. x1, x2, x3,... and I need to do the same operation with all of them - to multiply their components, ...
2
votes
3answers
113 views

Extract memoized results in the form of a rule

Lets say I define a function f with memoization. Is there some way to extract the memoized values? For example, ...
2
votes
1answer
120 views

Define function that counts recursive fibonacci

If I write count=0; fib[0]:=(count=count+1; 0); fib[1]:=(count=count+1; 1); fib[n_] := (count = count+1; fib[n-2] + fib[n-1]); Then I can ...
1
vote
2answers
126 views

Define the square of a function [closed]

Is there any good way to define the square of a function in M9? Usually one can write e.g. f[z_] = 3*Sin[z] etc etc. But is it possible to define ...
0
votes
1answer
31 views

Indexed variable with alternatives

I have a["tree"] := "oak" a["flower"] := "rose" a["dog" | "cat"] := "animals" I want that the last definition of a behaves ...
0
votes
1answer
63 views

How I can define a new function as a function argument?

I need to pass a function with t as independent variable as a function parameter and want to create a new function of the same through this provided the argument of another function. Here is my code. ...
0
votes
0answers
36 views

Can the value of a variable be made to persist between front end sessions? [duplicate]

For example, say I create a notebook with a cell a = 5 + 2 and then I close Mathematica, reopen the notebook, enter a new cell ...
3
votes
1answer
88 views

How to localize symbols on the right-hand side of Rule when using ReplaceAll?

I am frustrated by the following: {1, 2, 3.0} /. a_Integer -> a + 1 The a on the left side of the arrow is localized and ...
4
votes
1answer
133 views

When to use indexed variables

Still learning the fundamentals of the language I would like to ask you what advantages there might be in writing something like: a[1] = 2; a[2] = 4; a[3] = "x"; ...
2
votes
1answer
46 views

Quoting definition explicitly

I'm trying to quote a definition using DownValues, OwnValues, etc. Everything seems to be fine, except for temporary symbols' ...
0
votes
2answers
46 views

how to define roots of an equation as a function? [closed]

I need to solve an equation depending on 3variables in only one variables and define the roots as a function of the remaining variables? I used some thing like that: ...
0
votes
0answers
26 views

Get value for a variable from user inside a module [duplicate]

I am writing a module. When I run the module, I want it to ask for a variable, like I can in other programing languages such as C++ or Python. For example, in C++: ...
7
votes
0answers
69 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
2answers
127 views

Using a variable for two different purposes

I want to name a bunch of tables after the OEIS entries which describe them. Is there any way to use these names for both the table name and the link at the same time? The second line uses the ...
2
votes
3answers
235 views

Treat strings as variables?

I have a list of strings, {"x1", "x2", "x3", "x4"} And a list of linear equations: ...
15
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 ...
2
votes
1answer
99 views

How to define a matrix with all elements 0? [closed]

A matrix can be defined as M = Array[m, {3, 3}] which gives ...
0
votes
0answers
81 views

Is there a better way of creating/assigning variables programmatically than using strings and ToExpression?

For quite a while now I've been wondering how to assign variables programmatically, and I have finally figured out one way of doing this. For example in a game where you have a variable number of ...
0
votes
0answers
31 views

How to change $n$ variables with $n$ Buttons automatically [duplicate]

I was trying to make a little game, and I came accross this problem. The goal is simple. There are going to be $n$ number of buttons, and each one will change a value of one variable. For example, ...
1
vote
1answer
40 views

How to set the values into some variables from different lists [closed]

I have a list of Values and a list of variables. I want to set the Values into Variables. Assume the following code: ...
0
votes
0answers
53 views

How to hide global variables in package?

in the package I'm writing I have a list of global variables which should not be visible from a notebook. Here's an extract of the package: ...
0
votes
3answers
146 views

Clean-up Code / Reduce variables

I'm writing a playing card simulator of sorts, and everything works fine, but some Modules use a disgusting amount of variables. For Example: ...