Questions tagged [variable]

Questions on the use or manipulation of Mathematica variables (i.e. names associated with a changeable value). Use [variable-definitions] or [assignment] for questions on variable context localization, or assignment.

46 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
3 votes
0 answers
88 views

Module inside With, With inside Module, or Just Module?

In general, if one wants to define local variables and local constants, which of the following is the best programming practice in terms of performance and code "safety"? (Assume ...
Just Some Old Man's user avatar
3 votes
0 answers
123 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 ...
bjorne's user avatar
  • 569
2 votes
0 answers
72 views

how to understand the locality of variables in Mathematica

(in the first i should say may be the title is not very accurate) how to understand case like the following: ...
Aerterliusi's user avatar
2 votes
0 answers
69 views

a basic question about variable in Mathematica

I can't describe exactly the problem I'm experiencing, but this kind of problem has a remarkable feature, that is, commands which couldn't work in the before can be executed correctly when i turn off ...
Aerterliusi's user avatar
2 votes
0 answers
191 views

Creating new variable names, Symbol or ToExpression

One can create new variable names by Symbol : In[1] Table[Symbol["x"<>ToString[i]], {i,1,5}] Out[1] {x1,x2,x3,x4,x5} But it is also possible to ...
imida k's user avatar
  • 4,285
2 votes
0 answers
101 views

Issue with calling one notebook from inside another one

I am calling one notebook (N2) from inside another notebook (N1). The results are transferred correctly from the second notebook to the first one. But when I try to compare the results from the two ...
Mehdi Ebadi's user avatar
2 votes
0 answers
834 views

How to declare variables with plus/minus sign as subscript/superscript?

I am pretty new to mathematica, so please forgive me if I ask any stupid questions. I want to create a vector $a^{+}=[a^+_{k-2},a^+_{k-1},a^+_{k},a^+_{k+1},a^+_{k+2}]$ and then do some symbolic ...
Physicist's user avatar
  • 987
1 vote
0 answers
36 views

How to best query if an expression contains Symbol/variable

Say I have this expression, among many: ...
Tempus Nomen's user avatar
1 vote
0 answers
92 views

Full Information Maximum Likelihood - Under some other name in Mathematica

I have recently stumbled upon something called FIML - Full Information Maximum Likelihood. Apparently this methodology helps overcome missing variables provided the gaps are random. Searching the ...
Rogo's user avatar
  • 920
1 vote
0 answers
55 views

Error using list of discrete variables with WhenEvent

I came across an error when using a list of Discrete Variables with NDSolve and WhenEvent. As you can see in the minimal example, where I defined the 'testevent', when I use ...
Tim's user avatar
  • 115
1 vote
0 answers
101 views

A function that maps Held symbol to string

Rougly my question is about constructing a function that maps Hold[var] to "var" even when var has an assigned value. In details : ...
imida k's user avatar
  • 4,285
1 vote
0 answers
32 views

How to change expression of variable in output

I run the example: c = a - b; e^(a - b) This gives me e^(a-b). How can I do to let it output e^c
林怡君's user avatar
1 vote
0 answers
67 views

How to return a variable name and value from within a self-contained function block?

Abstract: I have viewed other solutions on StackExchange but none actually address using a fully self-contained function to return name and value of a variable. The only function that works requires ...
Jules Manson's user avatar
  • 2,457
1 vote
0 answers
43 views

Problem in importing function in NDSolveValue

I have a code for solving a system of 2 differential equations (sol1). Given that what's inside is a bit heavy, I define functions so that I can call them. My issue is that when I write everything ...
J.A's user avatar
  • 1,265
1 vote
0 answers
91 views

Execute a notebook with a changing variable

I have created a notebook with one fix variable that I want to run from 1 to 100. Every time the whole notebook (all cells) shall be executed for the given number. At the end of the notebook, it shall ...
Anne Wlite's user avatar
1 vote
0 answers
53 views

How to avoid import evaluation until if wil return true

My goal is to import a data from url that depends of 1 parameter, this initialy value is null or undifined en yo have to selec some popup and then the variable has value, what is the method to do that?...
Alberto's user avatar
  • 89
1 vote
0 answers
94 views

Settings to disable global scope

I am building a fairly large application in Mathematica, and globally scoped variables are causing issues. I would like globally scoped variables to be out-of-scope for my expressions, except by ...
f23rt24tg3qf's user avatar
0 votes
0 answers
25 views

How to find the argument dependance of an expression

Consider expressions such as X := f[n[1]][n[3]] g[n[7], n[1923]] I would like to construct a function that returns the list of $n$'s on which $X$ depends. I know ...
Adrien Martina's user avatar
0 votes
0 answers
48 views

Identify a condition among variables that satisfy an inequality

I have a symbolic function that produces the output a = (1 - e - mu/n) Log[(1 - e - mu/n)/(1 - mu/n)] + (e + mu/n) Log[((e + mu/n) n)/mu] If I substitute ...
Dotman's user avatar
  • 424
0 votes
0 answers
53 views

how to use subscripted variable such as a_i as the control of Manipulate?

I'd like to define a series of variables called $l_1$,$l_2$, etc., in Mathematica, using the "ctrl+_" shortcut. Moreover, I want to use these variables as the controls of a Manipulate[] ...
larry's user avatar
  • 725
0 votes
0 answers
40 views

Invalid Variable Error for Solve When Using Law of Cosines

I'm making a shadow simulator, and am using the Law of Cosines to calculate a certain angle in a triangle with two known widths and one known angle. I'm using Solve ...
LonelySpaceman's user avatar
0 votes
0 answers
66 views

Answer changes slightly when re-run

I am trying to resolve why I get slightly different answers when I re-run my notebook. Here is my full code: ...
LTB's user avatar
  • 1
0 votes
0 answers
51 views

Reusing local variables through Reduce and ToRules

Problem: I am interested in solving a system of linear equations through Mathematica. In my current test scenario, I am having trouble using the Reduce function followed by the ToRules command. I ...
Axion004's user avatar
  • 111
0 votes
0 answers
41 views

Scaling a variable multiplied by power series is not giving expected output

I have a power series getting multiplied by a variable, which gets scaled by the small parameter used in the power series. As an example, in the following dummy series: ...
Manpreet Singh's user avatar
0 votes
0 answers
82 views

Cannot Optimize where NSolve and NDSolveValue are involved with Multi-Variables

My Objective Function is Sqrt[Sum[((sol[[j]])^2), {j, 1, noofnode}]/noofnode] with variables v1, v2, v3, v4, v5, v6. But just ...
Sazedur Rahman's user avatar
0 votes
0 answers
139 views

How to Optimize a Finite Element Model with Multiple Variables in Mathematica?

Urgent Help, Please !!! I am attaching my codes for a Finite Element Model which needs to be optimized and the Objective Function ("of" in the code) has been mentioned at the last line of ...
Sazedur Rahman's user avatar
0 votes
0 answers
566 views

Help with Error: Recursion depth of 1024 exceeded during evaluation

I am quite new to Mathematica. Please excuse my mistakes. I would appreciate if you could help me with the following set of commands. ...
grkcn's user avatar
  • 1
0 votes
0 answers
43 views

how to delete a variable programmatically in a notebook from another notebook

how to delete a variable programmatically in a notebook from another notebook? c = b; I have already tried Remove[c] but ...
Mohammad Shahbazi's user avatar
0 votes
0 answers
105 views

Minimizing a function and plot it

I have a long expression, depended on 3 different variables say "a", "b" and "p". Just as an example, a part of this expression is: z = p * Cos[x] * Sin[y]. I'm going to ...
user79424's user avatar
0 votes
0 answers
54 views

Assign Variable to NSolve

I'm looking to create an interactive region plot in Mathematica, and it's quite a complicated region (seen below).. The variable p is actually a function of y, and it's too hard to solve analytically. ...
Dmlawton's user avatar
0 votes
0 answers
56 views

Replace the output of a module containing local variables by their actual value

I want to construct a function as the output of a Module, but I obtain the local variables as part of the output. This is a problem when I try to construct many of these functions in a parallel table, ...
julian haddad's user avatar
0 votes
0 answers
83 views

Issue with several replacements in a function under certain conditions

I am trying to define a function (reduce[x]) which does several substitutions, depending on the values of certain parameters. Concretely, consider an expression x, which contains an arbitrary number ...
Jordi's user avatar
  • 1
0 votes
0 answers
626 views

Using an if statement to assign a value to a variable

New Mathematica user here. I'm using some code from a colleague and editing it to give me more specific results in finding the zeros of a complex polynomial. I am attempting to find a way to assign a ...
elpitts's user avatar
0 votes
0 answers
58 views

Variables for multiple data files plotting using same Mathematica notebook

I am not an expert in mathematica, I have this following code. As you see I import a text file under the name "MyPoint1", plot with "pAll" then I do some more calculation with more variables and ...
Erfi's user avatar
  • 121
0 votes
0 answers
90 views

ReplaceAll Not Working Correctly

I'm trying to use replaceall to redefine my expression in terms of a separate variable.. ...
Toby's user avatar
  • 1
0 votes
0 answers
33 views

Bounding Solve results to named variables

How can i bound results of my Solve function to variables properly? This metod works but causes unexpected troubles i struggle to resolve ...
Карен Ла Фон Даль's user avatar
0 votes
0 answers
68 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], ...
Anand's user avatar
  • 13
0 votes
0 answers
473 views

What are the valid symbol names for packages?

Regarding to the message: ...
S.V.'s user avatar
  • 101
0 votes
0 answers
101 views

The conditions used in Sum or ParallelSum: Calling a function/variable

For some reason, I encounter a problem when doing the Sum and ParallelSum (or doing the Do or ParallelDo, e.g. such as the issue here), I figured that the potential cause of the problem can be ...
wonderich's user avatar
  • 923
0 votes
0 answers
91 views

to reduce the unknowns of a set of equations with several symbolic coefficients, e.g. using the GroebnerBasis

I have a set of $4$ equations with $4$ unknowns $\theta_1$ to $\theta_4$, and would like to eliminate the number of unknowns, to get a smaller set of equations, e.g. $n$ equations with $n$ unknowns, ...
larry's user avatar
  • 725
0 votes
0 answers
794 views

Extract fit error from parameter table to use as a variable

Is there anyway to extract the fit error and store it in a variable. I have done something similar to use actual fit results as ...
user27119's user avatar
  • 2,500
0 votes
0 answers
49 views

Similar Variable Names

I have variables $X1,...,X10$ and $X1hat,..., X10hat$ in a system of equations. How can I refer to these variables in a summation? I am looking for something like: ...
Hossein's user avatar
  • 281
0 votes
0 answers
718 views

Colors of variable mathematica

Suppose that I have an equation which goes like this: x = 2; yp = 2; y_p= 2; a = x + yp + y_p; Usually, once the variable is defined it will be of blue color and ...
sreeraj t's user avatar
  • 303
0 votes
0 answers
76 views

Using sub-scripted variables in functions

Is it possible to use subscripts in Mathematica functions, for example f[Subscript[x, a] _] := x^2 However this doesn't seem to work, is there a way to allow ...
user27119's user avatar
  • 2,500
0 votes
0 answers
105 views

Best practice for passing variables to many functions?

I am rewriting an application in Mathematica. The previous version used global variables, which I find distasteful, but to avoid it I am needing to pass several static Datasets and Associations around ...
Rick R's user avatar
  • 407
-1 votes
1 answer
129 views

Symbolic representation of Class Conditional Probablity as a variable

What is the best way to a create a symbolic variable to represent Class Conditional Probability in Mathematica e.g. $p(A|B)$
Saqib Ali's user avatar
  • 275