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
0
votes
1answer
23 views

Getting error messages form Set while trying to implement the bisection method with a For-loop

My objective is to build a function using modules that runs the bisection method. I have a working bisection method but when I try to implement it as a module I keep getting this error and I can't ...
0
votes
0answers
27 views

Return local variables from a function built with Module [closed]

I have a generic function: f[a_,b_]:=Module[{l,m,n,o,p}] How can I have returned: l, m and p by using: ...
1
vote
1answer
33 views

Multiple functions compact form

I have a sort of silly question... I need to define two functions in the following way ...
0
votes
2answers
58 views

Save a Derivative

I have defined the derivative of a function Derivative[1][f][x_] := Sin[x] How can I save this definition in a file? Derivatives are not included in ...
2
votes
4answers
105 views

How can we make the input of a function multiple lists?

I want to create a function that takes inputs that are multiple lists of ordered quadruples. For example, when we run the code our input line should read something like inputs[{2,3,4,5},{6,7,8,9},...} ...
0
votes
1answer
42 views

Compact notations for multiple variables

Why does this work Manipulate[ListPlot[{a[1],a[2],a[3]}], {a[1], 0, 1}, {a[2], 0, 1}, {a[3], 0, 1}] But this doesn't? ...
0
votes
1answer
38 views

Defined function keeps the variable

I'm a beginner at Mathematica, and I have a problem finding the roots of a function for a specific variable (using Jens' findAllRoots function). Due to the nature of my problem, I need to compute ...
6
votes
3answers
176 views

KeyExistsQ[] but for functions?

Is there a good way to check if, say, f[5] has been defined if f is a function, similar to ...
6
votes
3answers
405 views

Create variables in a for loop

I am very new to mathematica, but it would be much easier for me to use For loops in order to create variables. My train of thought was simple, but apparantly does not work. Let's say I defined these ...
0
votes
0answers
24 views

Number of values stored in a function

Suppose I run this: f[0] = 1; f[n_] := f[n] = 2 f[n - 1]; f[1000] Now there will be 1001 values stored in f, and ...
2
votes
1answer
37 views

How to Append the value of a variable and not the variable itself

So lets say I have a = Some complicated code that changes list = {} AppendTo[list, a] Obviously it would give me ...
3
votes
1answer
26 views

Referencing data in sets of sets

Given a data set how to assign definitions to the subsets. For instance given the data data = {{0, 1, 1}, {0, 1, 1}, {1, 1, 0}, {0, 1, 1}, {1, 1, 0}} if {0, 1, 1} ...
13
votes
4answers
739 views

When is a symbol a Symbol? Is there an easy Mathematica way to test if an object is a symbol sort of like a SymbolQ?

Yes I know there is no built-in native function called SymbolQ (but JavaScript does). However, could one be simulated to work for most cases? I often rely on ...
7
votes
1answer
88 views

Is there something wrong with DistributeDefinitions?

I have the following code, which fails to distribute the DownValues for the symbol f. Could anybody please explain what is wrong. ...
0
votes
1answer
59 views

Subscripts use to make expression readable [duplicate]

I am trying to write a function in mathematica which depends on different parameters. For example $$f(x_1, x_2, x_3, x_4, x_5)= 2x_1+\sin(x_2)+x_3*x_4-x_5^{-1}$$ (My actual function has 12 such ...
2
votes
1answer
116 views

Functions without arguments [duplicate]

In the course of a project recently I had to use a particular function u[x, t] a number of times. Because in mathematics I would typically write this function as $...
2
votes
1answer
60 views

Are symbols automatically generated when defining a variable in the global context and what are symbols?

Abstract: I have noticed something really tricky with Mathematica and the documentation for symbols is short on clearing the confusion. It likely reveals what symbols are but it's not very prominent. ...
10
votes
1answer
226 views

How to clear all definitions matching f[1, …] but not f[2, …]?

I would like to clear all definitions of the form f[1,...] in such a way that f[2,...] remain unaffected. The two methods I know ...
0
votes
0answers
40 views

Definition of a real variable

I would like to calculate a definite integral with a real parameter "a". I tried Refine[Element[a, Reals]] and Simbols [Element] Reals but the yield was a ConditionalExpression dealing Im[a] and Re[a]...
0
votes
0answers
31 views

Defining a function with certain regularity (e.g. smooth)

My goal is to understand how Mathematica computes limits that would require differentiability assumptions on functions (for, for instance, L'Hopital or Taylor Series). Consider, for instance, the ...
1
vote
1answer
46 views

Simplify terms with delayed and immediate function definitions

Say I want to define a function fwith input x but also involving parameter p not yet ...
4
votes
2answers
56 views

Move definition from one context to Global`

Suppose we have the following package ABC.wl. BeginPackage["ABC`"] Begin["DEF`"] f1 = 0; f2[x_] := x + 1 End[] EndPackage[] ...
8
votes
1answer
76 views

Local variables in sums and tables - best practices?

Stumbled on Local variables when defining function in Mathematica in math.SE and decided to ask it here. Apologies if it is a duplicate - the only really relevant question with a detailed answer I ...
0
votes
1answer
43 views

SetDelayed using local variables

I'm trying to define MakeBoxes for a bunch of functions all at once, but wish to do so within a loop as in the following example: ...
3
votes
1answer
42 views

New variable in With structure appear as global, and many other strange things I don't understand

I thought I know With and Module until I see this example on Wolfram Documentation. Below is a demo code: ...
0
votes
0answers
29 views

Evaluating global variable within a module

I'm trying to work with something like the following: a = b; f[x_, b_] := Module[{N}, N = Abs[a]; 10 N ] f[1, 1] The output of running this is: ...
0
votes
0answers
44 views

Set of multivarible expressions to be re-expressed a single variable

I have a set of expression such as $\frac{3x+y-z}{6x}$ and $\frac{3 x-y+z}{12 x}$, which can easily get re-expressed as $p$ and $(1-p)/2$, where $p=\frac{3x+y-z}{6x}$, but is there a way to find this $...
0
votes
0answers
39 views

Problema simulating FindRoot

I am writing a procedure that simulates the findRoot built-in function using the same code that appears at chapter 6 of $\textit{Programming in mathematica}$ by Paul Wellin. The code is the following....
1
vote
1answer
27 views

syntax error when defining a list of matrices: “…cannot be followed by..”

I am literally just defining a list of matrices, but seem to run into the following error when adding the last matrix. (so to be clear, I get no error when I take out the last matrix entry). What's ...
0
votes
1answer
40 views

Assign variable to solve [duplicate]

I would like to assign my result from equation. I tried /. and := but it gives me empty variable. How can i fix it?
1
vote
1answer
33 views

Getting a stored variable from its value

Given a numerical value, is it possible to check whether that value is stored in (or defines) some variable in the notebook? Maybe if I could list all of the defined variables, then I could simply ...
2
votes
1answer
112 views

Mathematica Won't Recognize a MeshRegion

I've implemented the code in the top answer of this question on the Plateau problem in differential geometry, and it works with the example shown in Example 1, so there is nothing wrong with the code. ...
1
vote
0answers
54 views

How to define an Intermediate Variable [duplicate]

I want to find the relationship between several parameters. But I don't know how to define an Intermediate Variable. For example: I want to know the relationship between x and {y,z} which will satisfy ...
0
votes
1answer
29 views

Avoid an Error Message when Importing

Consider the following code Button["Import", file = SystemDialogInput["FileOpen"]; data = Import[file], Method -> "Queued"] which yields a button which, ...
0
votes
0answers
11 views

Min of a set defined with conditions

I would like to define this parameter inside a function: $R = \min\left\lbrace i \in \left\lbrace 1,\cdots,n \right\rbrace \; : \; ((p+i)\mod n) \; \neq a_{j} \; \forall j \in \left\lbrace 1,\cdots,m ...
1
vote
0answers
79 views

Issue with Solve, NSolve, FindRoot

I have this code that I've been trying to get working for some time. I asked some questions before which helped but still struggling! ...
0
votes
1answer
34 views

Issue with variables/functions in solving equations

I've been posting some questions all around issues with defining and using variables/functions in Mathematica. Based on the answers/comments I got I still cannot make this simple code work... Why is ...
1
vote
1answer
59 views

Table of Variables within Manipulate

Given a certain number n, I want to define n controls within Manipulate with the correct ...
3
votes
1answer
64 views

Automatically generating and labelling controls in Manipulate

Consider the following code ...
2
votes
1answer
63 views

Store boolean expression into a variable

My purpose is to use a boolean expression as a requirement that a pattern must comply. The requirement is c1 == "a", and I am using it to select a string from a ...
0
votes
0answers
21 views

Plot 2 functions, and function defining practise [duplicate]

I would like to plot the f1 and f2 functions on the same plot. The problem is that all functions are green on the plots. Is this a good practice to define the f1 and f2 functions and the rules like ...
4
votes
3answers
90 views

Is it possible to use a previously defined value in subsequent definitions of a `Block`?

Is it possible to use a previously defined value in subsequent definitions of a Block? According to syntax coloration, this should work as expected, that is, ...
0
votes
0answers
50 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 ...
4
votes
1answer
75 views

Defining list of new variables at once (in a loop?)

I have a list of solutions Subscript[x, 1][t], i = 1,...,n (n given). I would like to use these variables to define new variables such as: ...
2
votes
2answers
51 views
3
votes
1answer
70 views

How to access all instances of a defined function

This should have a simple solution, but for some reason I cannot find how to do this. Let's say I have a "function" where I have defined values (in my actual example I have many instances of this, ...
0
votes
0answers
37 views

Series expansion of explicit functions

For the following input, zv[u_, v_] := v + zv1[ u, v]/u; mvu[u, v] := D[zv[u, v], u]; Series[mvu[u, v], {u, 0, 1}] the output is ...
1
vote
1answer
94 views

Basic Question: how should I read this instruction?

I'm very new at using Mathematica and it's not my Job. It's just something I like. ...
0
votes
1answer
37 views

unknown variable in a recursion relation

I have a code as follows ...
0
votes
1answer
45 views

Reversing the flow of the equation sign. Compacting an equation. Choosing which variables to show

Here's a simple example of what I'm trying to get at with that mysterious title. I start off with a Hermitian matrix that I derived analytically ...

1
2 3 4 5
9