Questions tagged [variable-definitions]

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.

Filter by
Sorted by
Tagged with
1
vote
2answers
35 views

Generating random variates inside summation

I'd like to generate a table of sums which each a non-correlated, normally distributed random variate inside. Here is the sample code: ...
1
vote
1answer
72 views

Expectations of sums

I would like to use Mathematica to derive some bounds on empirical estimators, such as $E[Y]$ where $Y = \tfrac1n\sum_{i=1}^n (X_i - X)^2$ and $X = \tfrac1n\sum_{i=1}^n X_i$. For a moment I thought ...
6
votes
2answers
383 views

Is it possible to Clear (recover memory from) a specific index to a variable, while leaving other indices to the same variable untouched?

Consider the following method commonly used to clear a typical variable: ...
6
votes
1answer
211 views

Best way to write an equation with subscripts and superscripts

This post is not about a specific Mathematica problem but about to develop the best way to enter mathematical equations with subscripts and superscripts. I have a ...
2
votes
0answers
48 views

Why doesn't ClearAll[“Global'*”] remove all variables? [closed]

Consider the following code : In[19]:= a = 2; In[20]:= ClearAll["Global'*"]; In[21]:= a Out[21]= 2 As you see, the variable a hasn't been resetted. Why ? ...
1
vote
1answer
30 views

Replace series with restrictions

I am trying to implement a code where I have the following problem: Consider I have the following series, which I can express as follows: $$ \sum_{j<k} x_j^4 x_k^4 = \frac{(\sum_j x_j^4)^2 - \...
0
votes
1answer
52 views

Defining Multiple Variables with the Same Value

I know we have a := 1 b := 1 but is there some 1-liner shorthand, akin to: ...
1
vote
2answers
65 views

Collecting terms from expression with indexed functions

Say I have an expansion of terms containing functions y[j,t] and its derivatives, indexed by j with the index beginning at 0 ...
8
votes
1answer
190 views

Fitting multiple data with model and NDSolve with different initial conditions, and other shared parameters

I know that there are already questions about fitting multiple datasets and about NDSolve and about shared and non shared parameters, but I tried to apply them and some things are still not clear. ...
2
votes
0answers
28 views

Issue passing a list to last argument of ImplicitRegion (Scope issue?) [duplicate]

This is a very strange issue I'm having trying to pass a list as an argument to Mathematica's "ImplicitRegion" function. Here's the issue: ...
0
votes
0answers
36 views

Defining a function through an ODE containing unspecified operators

I want to do some algebra using a function only defined through a DE containing unspecified operators. The DE is $$ \partial_zu(z) = \left[\hat{D}+\hat{N}(z,u)\right] u(z). $$ Here $u$ lives in ...
0
votes
0answers
26 views

List of all items stored in kernel

In Matlab, there is a window on the side that contains all of the variables stored in the workspace. Is there something equivalent in Mathematica? I am imagining a command kind of like DownValues or ...
1
vote
1answer
55 views

Mistake in calculating a variable from a plot

I have data from a knife-edge measurement technique, Power vs. knife position, and I want to obtain the beam radius. ...
2
votes
1answer
128 views

How do I create a variable that uses I?

I'm planning on working with a set of non-linear differential equations. A few of the equations look like: Mathematica tells me that I is protected. Is there any ...
0
votes
1answer
37 views

Save nested Solve results into variables (edited)

I have some solve results stored in the ptes variable: ...
1
vote
1answer
24 views

Use ChoiceDialog to assign value to a variable within a function

This may be a routine answer that I have overlooked, but I am stumped... If I want to write a function using ChoiceDialog, how can I use what ChoiceDialog returns (true or false) to either set a ...
1
vote
1answer
35 views

Defining a function that outputs a matrix, and later finding its eigenvalues

I am trying to do the following: I have a simple 2x2 matrix that depends on three parameters (physically -- momentum coordinates kx, ky, kz). Then I want to replace each of these parameters by a ...
1
vote
1answer
87 views

How to define a complex function with assumptions?

I'm trying to define a complex function to be able to do analytic calculations. Specifically, I want to define a function $A(x,t)$ in the complex plane with argument $\theta(x,t)$ and modulus $R(x,t)&...
2
votes
1answer
46 views

Problem with defining a simple linear operator

I need to define a linear operator, which should have very simple linearity: myOp[Plus[f_, g_]] := myOp[f] + myOp[g] myOp[a_ f_[x_, t_]] := a myOp[f[x, t]] where ...
1
vote
2answers
50 views

How to define multivariable vector funtion? [closed]

I would like to define a function of variables having two components as $u(x,y) = (f(x,y),g(x,y))$. I defined such a function as u[x_, y_] := {f[x, y], g[x, y]} ...
11
votes
2answers
404 views

How can I make assignments persist across sessions?

Yesterday, I imported a large set of data into a Mathematica notebook and stored each imported list of numbers in a function. For example, I would map a list like ...
1
vote
2answers
125 views

Can one define 0 Log[0] = 0?

With reference to this post, can one define 0 Log[0] = 0 in Mathemtica?
1
vote
2answers
113 views

VectorDensityPlot, [closed]

I'm trying to plot the following function for two different values of variable m. However, it seems the second figure never appears. Weirdly, I noticed that real numbers are being attributed to ...
0
votes
2answers
38 views

How can you define a function with variables and put it equal to a function that is already defined? [closed]

Lets say you have a function: f = x^2 + y^2 Now I want to define a new function of x and ...
0
votes
0answers
32 views

Is there a difference between these two ways to define a function? [duplicate]

(I took this example from another question) f[0] = 0; f[n_] := f[n] = DigitCount[n, 10, 1] + f[n - 1]; f[1016] I notice that this example defines f(n) in a ...
1
vote
1answer
41 views

Plotting a complicated function defined in terms of other defined quantities

Perhaps this question will be too broad or poorly asked since it is about some very simple problems and I apologize if that is the case. So, I'm just trying to plot the curve of a complicated and ...
0
votes
0answers
20 views

Seeing definitions of built-in functions [duplicate]

Possibly a very amateur question, so I'll apologise in advance. I'm reasonably new. I'm trying to write a Dot equivalent of ...
2
votes
3answers
91 views

Globally Defining a Variable that Depends on Arguments of Functions [duplicate]

I have many delayed-defined functions of many variables, and all the functions share a term containing some of these variables. Thus, I would like to just call the term ...
3
votes
2answers
73 views

Changing the values of variables throughout a notebook

I have a model with many parameters, and I'd like to see how the model changes when some of those parameters change. Right now many of those parameters are set to prescribed values, i.e., ...
0
votes
1answer
37 views

Factoring out a parameter

I have some function: f[a_,b_,c_]:=Sqrt[a^2+b^2+c^2] Is there a way that I can factor out parameter (variable) b like this: <...
0
votes
1answer
41 views

Relations between Function Variables in Computations

I have the relation λ=c/f, respectively f=c/λ and a simple function n[λ_]:=λ²+1. I'd like to differentiate the function with respect to f, then plot it as a function of λ again. For this, I can define ...
1
vote
1answer
68 views

How to define a variable to be a function of all the arguments but one?

I have several variables (coordinates) $x_1, x_2, x_3, x_4, z$ and a lot (21, to be precise) functions $g_i$ which are assumed to depend on $x_1, x_2,x_3, x_4$, but not on $z$. I also have a ...
1
vote
1answer
47 views

Why does LinearModelFit give me an equation in $z$ rather than $x$?

I am working on a Mathematica notebook and making graphs for my lab. I can't make a graph for my linearized data as LinearModelFit gives equation in ...
1
vote
1answer
43 views

Using both subscripted and non-subscripted variables in an equation

I'm getting started with Mathematica, as I have been using Maple in the past. Is it possible to define two variables $\alpha_1, \alpha_2$ and then still use $\alpha$ as a parameter of a function and, ...
1
vote
1answer
43 views

Question about ListPlot of variables [closed]

My question is trivial but I don't seem to be able to get the answer. Suppose that I do a numerical computation (division of some numbers that come from the numerical solution of an NDSolve or ...
2
votes
1answer
74 views

Get the name of symbol inside a function [duplicate]

I have a list t1Funcsv0={0.10000000000, 1.00000*10^-7} and I have a function ...
1
vote
1answer
30 views

Evaluation of parameter inside FindMaximum

Why does this work: Table[ FindMaximum[x^2 - y^2, {y, 1}][[1]], {x, 1}] While this does not: ...
4
votes
2answers
160 views

How to use a variable in a function that can't be clobbered by variable name collision?

Not really sure what the right question to ask is. But here's what I'm having trouble with: ...
1
vote
0answers
40 views

How to define a variable $x$ such that $Abs[x]<1$ and use this globally without having to re-write it again and again?

I am writing a code or a calculation of a very complicated function and my main variable is $x$ such that $-1<x<1$. This assumption has to simplify my final answer a lot, but since the final ...
1
vote
1answer
70 views
0
votes
0answers
54 views

Assign a variable to an expression in Mathematica

I have the following matrix {{a^2 + b + \[Sqrt](m + n) + 5, 23 x + 7 a}, {14 b, a^2 + b + \[Sqrt](m - n) + 5}} I want to replace the expressions ...
6
votes
2answers
544 views

Confusing behavior when passing a variable vs. inlining a function call

Newbie question here. Consider the following two functions: ...
10
votes
1answer
133 views

Attempts at backwards compatibility

I have written a package in Mathematica 11, and I would like to provide some backwards compatibility to earlier versions. An example is the function Echo. ...
0
votes
2answers
80 views

how can I define a symbol as a global real number?

Say there is a complex number a=x+I, where x is a real number. Then b=Join[{a},{1+I}], and I ...
17
votes
2answers
325 views

When to name a variable with $

There are some symbols in the Wolfram Language that start with $, including $Abort, ...
2
votes
1answer
73 views

How to reuse variable - Error: Pattern appears on the right-hand side of rule [closed]

I do not know enough about Mathematica to understand why the following statement won't save the variable for me for later use: x_fake = Table[i, {i, 1, 100}] It ...
1
vote
1answer
51 views

Mathematica is picking up variable definition from other files

Mathematica is using definitions from other open files in the same folder. I want variables not defined in a particular file to be treated as undefined variables. I do not want Mathematica to pick ...
16
votes
2answers
346 views

Different strategies to get a clean Kernel. Quit, Exit, ClearAll, Remove, CleanSlate?

Often new users face problems with lingering definitions that, if unaware, may cause unexpected and frustrating behaviour. There are several answers that illustrate different aspects of the solution, ...
0
votes
1answer
295 views

FindRoot fails 100 iteration precision

I am attempting to find roots of a complex equation that involves exponential functions and small approximation values. I have had success using FindRoot for values ...
6
votes
1answer
194 views

Create local alias for variable

I have a function whose parameters are passed "by reference" Clear[foo] SetAttributes[foo, HoldFirst] foo[t_] := t = 10 Is it possible to create an alias for <...