Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

1
vote
2answers
99 views

VectorDensityPlot, [on hold]

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
36 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
28 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
39 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
76 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
58 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
27 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
56 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
45 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
38 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
37 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
58 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
28 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
158 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
39 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 ...
0
votes
0answers
53 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
535 views

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

Newbie question here. Consider the following two functions: ...
0
votes
0answers
17 views

How ValueQ works? [duplicate]

I have some generated string: StringJoin["Z", ToString[j], "[", ToString[i], ",", ToString[k], "]"]] I do expression from this string: ...
10
votes
1answer
122 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
64 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
315 views

When to name a variable with $

There are some symbols in the Wolfram Language that start with $, including $Abort, ...
2
votes
1answer
57 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
44 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
302 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
0answers
38 views

How to use the same variables in another function, where earlier variables have been defined as global variables?

I want to do 2nd derivative of the function f1 w.r.t l and then integrate the function w.r.t. l1. Actually both the functions ...
0
votes
1answer
194 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
165 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 <...
0
votes
1answer
54 views

How to define the function [duplicate]

How to define this function? $$ A_{n,k}:= \begin{cases} 0, & \mathrm{if } \ k<0 \\ 1, & \mathrm{if } \ k=0 \\ (2k+1)\binom{2k}{k} \sum_{n\geq j\geq 2k+1} A_{j,n} \binom{j}{2k+1} ...
0
votes
0answers
220 views

Using loop index for variable names?

I am trying to generate different variables in function of a loop index. In example: generating a list with var1 = 1, var2 = 2, ... ...
2
votes
3answers
117 views

Using Association[] in an Immediate Function

I have an Association[] which is the result of an intensive computation. Its values include the variable x and I would like to ...
3
votes
2answers
69 views

How to set a particular element of a list to a number?

I have a list {a,b,c,d}, and I want to set the 1st element and the 3rd elements equal to 5 and 8, respectively, leaving 2nd and 4th as they are (...
0
votes
1answer
81 views

How to define the result of Solve as the variable [duplicate]

Consider the operation Solve[f[x,y,z] == 0, x] I want to put the solutions for x obtained by this operation as the new variable. I tried to use ToString, ...
0
votes
1answer
83 views

Writing a recursive block 'while' [closed]

I tried to write a program according to the definition using operator While, but it returns zero for each d an ...
1
vote
1answer
45 views

Using Variables[] as the argument of Plot[]

I want to use the Variables[] function to extract the name of the variable of a function, such that I can use it later, e.g. in a ...
1
vote
1answer
97 views

Higher Order Taylor's Method help

I'm really new to Mathematica, so bear with me here. I'm trying to solve an initial value problem given the first derivative of a function: y' = (y^2+2y+1)/(x^2-2x-1). I understand how the method ...
4
votes
2answers
261 views

Function to create a square matrix with and assign values

I am trying to create a function that returns a matrix as in the description below. The function has five inputs: M: name of the matrix n: size of the matrix nxn a, b, c: integer numbers with $0 \le ...
0
votes
1answer
37 views

Create list of elements with dependence on a variable

I'm aware that we can make a list of elements: x = Table[Symbol["x" <> ToString@i], {i, n}]; This returns x = {x1,x2,x3} when n = 3. What I want is to be ...
1
vote
1answer
53 views

Variable shift for a function of n variables

I have a polynomial in n variables, L[1],...,L[n]. Starting from an index j, I want to shift ...
9
votes
1answer
202 views

Finding a variable name given its numerical value

If I set up a = 1 Is there any command to get "a" by typing value 1? Another example. ...
0
votes
2answers
96 views

Defining a list without knowing the number of elements

Let $N$ be a natural number $\ge 1$. I have two questions: How can I define a list with variables $p_1,...,p_n$? How can I define an element $a\in\mathbb{C}$ such that $a⁶=(-1)^n?$
0
votes
1answer
60 views

Run Block of Code in For Loop

Suppose I want to conduct an experiment 10,000 times in which a random sample of size $n=20$ from a beta distribution is collected and then the values of four different estimators are collected. At ...
0
votes
1answer
48 views

Is there any way to define vector constants that are not be deleted by the function ClearAll?

I'm sorry if my question is akward, it's my first question here. :) I wanna use unit vector of spherical coordinates not using any functions. (r hat) Cross (theta hat) for example. Is there a way that ...
2
votes
1answer
57 views

Strange behaviour of ValueQ inside loops

TL;DR: I have a series of variables $x_1, x_2, x_3, \dots$ which to which I assign values inside a loop. However, when I use ValueQ to determine which values I've ...
5
votes
2answers
61 views

OwnValues for Set and SetDelayed

I am unclear about the OwnValues for Set and SetDelayed. ...
0
votes
1answer
66 views

Different solutions for same integral when using different variables

Consider the following integral: $$I := \int_1^2 \frac{1}{\sqrt{(2-x) (x-1)}} \, dx.$$ The solution of this integral is $I = \pi $. I typed this integral into Mathematica in a more general form: <...
0
votes
1answer
56 views

Issue with variable recognition

Why are the variables r,s,u,v identified differently in the definitions of F2,G1,G2?
1
vote
1answer
117 views

How to evaluate user-defined functions with variables?

I have an extremely simple question, but I couldn't find anything anywhere, maybe I didn't know what to search for, so feel free to mark it as duplicate if there is a duplicate. Let's say that I ...