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.

39 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
3 votes
0 answers
79 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 ...
user avatar
3 votes
0 answers
66 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 ...
user avatar
  • 559
2 votes
1 answer
75 views

Define variables dynamically to compute a function

Let's say I have defined a function $W(p, q)$, where $p$ and $q$ are integers between (and including) $0$ and $2$ and the function takes me to a real number. Upon an input $n$, where $n$ is a positive ...
user avatar
2 votes
1 answer
107 views

Why some variables get substituted and others don't

I was running into some trouble with my math and I whittled it down to this nugget: ...
user avatar
  • 31
2 votes
0 answers
57 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 ...
user avatar
2 votes
0 answers
610 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 ...
user avatar
  • 937
1 vote
0 answers
73 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 ...
user avatar
  • 579
1 vote
0 answers
30 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 ...
user avatar
  • 115
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
user avatar
1 vote
0 answers
51 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 ...
user avatar
  • 1,787
1 vote
0 answers
42 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 ...
user avatar
  • 1,225
1 vote
0 answers
87 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 ...
user avatar
1 vote
0 answers
52 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?...
user avatar
  • 89
1 vote
0 answers
76 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 ...
user avatar
0 votes
0 answers
67 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 ...
user avatar
0 votes
0 answers
95 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 ...
user avatar
0 votes
0 answers
91 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. ...
user avatar
  • 1
0 votes
0 answers
33 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 ...
user avatar
0 votes
0 answers
100 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 ...
user avatar
  • 2,451
0 votes
0 answers
63 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 : ...
user avatar
  • 2,451
0 votes
0 answers
33 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 ...
user avatar
0 votes
0 answers
42 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. ...
user avatar
0 votes
0 answers
44 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, ...
user avatar
0 votes
0 answers
79 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 ...
user avatar
  • 1
0 votes
0 answers
164 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 ...
user avatar
0 votes
0 answers
56 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 ...
user avatar
  • 111
0 votes
0 answers
64 views

ReplaceAll Not Working Correctly

I'm trying to use replaceall to redefine my expression in terms of a separate variable.. ...
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 ...
user avatar
0 votes
0 answers
60 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], ...
user avatar
  • 13
0 votes
0 answers
347 views

What are the valid symbol names for packages?

Regarding to the message: ...
user avatar
  • 101
0 votes
0 answers
88 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 ...
user avatar
  • 823
0 votes
0 answers
72 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, ...
user avatar
  • 675
0 votes
0 answers
639 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 ...
user avatar
  • 2,291
0 votes
0 answers
47 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: ...
user avatar
  • 261
0 votes
0 answers
478 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 ...
user avatar
  • 171
0 votes
0 answers
75 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 ...
user avatar
  • 2,291
0 votes
0 answers
92 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 ...
user avatar
  • 387
0 votes
0 answers
113 views

How to provide input as a set and get a set as output too?

Friends here is the code given to a problem which i have been trying to solve lately but in the first equation i want value of 'k' to be [-1,1] or it should take every value from -1 to 1. And i know ...
user avatar
-1 votes
1 answer
126 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)$
user avatar
  • 275