Stack Exchange Network

Stack Exchange network consists of 175 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.

2
votes
1answer
123 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
32 views

Save nested Solve results into variables (edited)

I have some solve results stored in the ptes variable: ...
1
vote
1answer
19 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
23 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
63 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
43 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
48 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]} ...
6
votes
2answers
247 views

How can I make assignments persist among 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
85 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
108 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
37 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
30 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
77 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
65 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
30 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
61 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
42 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
40 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
67 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
159 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
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
538 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
126 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
69 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
317 views

When to name a variable with $

There are some symbols in the Wolfram Language that start with $, including $Abort, ...
2
votes
1answer
63 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
46 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
314 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
248 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
176 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
56 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
291 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
120 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
72 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
109 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
85 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
116 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
271 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
40 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
58 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 ...