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
2 votes
0 answers
54 views

Argument value loss using Listable C-Compiled Function

In my recent studies, I have come across a very strange anomaly with C compiled functions. When I call a function that has the 'Listable' attribute while global variables are accessed through ...
1 vote
0 answers
38 views

checking if a variable is defined

How can I check if a variable is defined? Definition[foo] produces: Null, but: ...
2 votes
5 answers
237 views

Repeating definitons of variables

I have the piece of definitions y = 1; x = 2; n = 2; a := (y^(x - 1) + n)/(y^(x - 1) + y^(x - 2)) I want to keep defining y as a by doing: ...
2 votes
1 answer
81 views

Defining function for decimal value k[0.5+0.5]

k[1 + 1] = 2; k[1 + 0.5] = 1.5; k[0.5 + 0.5] = 1; {k[2], k[1.5], k[1]} // TableForm 2 1.5 k[1] Can you explain this phenomenon? I think the output should be ...
  • 3,561
1 vote
1 answer
68 views

How to avoid using the principal branch?

How can I make Mathematica to use $Log[-1]=i\pi+2i\pi*n$ with $n\in\mathbb{Z}$? Currently, mathematica set $Log(-1)=i\pi$ and when I try to redefine the value of $Log[-1]$ I get the message "Set::...
  • 121
0 votes
0 answers
67 views

Can you dynamically create variable names in Mathematica? [duplicate]

I was wondering if there is a way of Mathematica to read a string or number and create variable with that name. For instance imagine that I have a file with the word data1. I would want to create a ...
2 votes
2 answers
106 views

The way of converting a string to a variable in a loop?

I have 60 txt files which I want to import them into Mathematica using a Do loop. Each file contains some numbers (more precisely, a list of numbers). I want to put ...
  • 1,228
0 votes
1 answer
81 views

Global order setting

I'm working on mathematical models using many alphabets and Greek characters as parameters or variables. However, The outputs show them in undesired order. Here are some examples: ...
  • 1
2 votes
2 answers
211 views

How to implement Newton's Identities

I need to produce identities related to Newton's Identities of arbitrary order. More specifically, I need the identities in the following image for an arbitrary n: What I can't quite wrap my head ...
  • 1,496
1 vote
1 answer
86 views

My ParallelDo does not work

I have to do a lot of calculations that take lot of time, and using a Do loop is simply too long. It is the first time I am using ...
  • 33
1 vote
1 answer
60 views

Initializing a system of abstract functions with a for loop [closed]

I am trying to initialize a collection of abstract functions $\theta_k(t)$ in a variable $t$ where $1\leq k\leq n$. I cannot define them explicitely; the entire point is that I want to numerically ...
  • 111
2 votes
1 answer
99 views

SystemModelLinearize

The following are the state matrices A and B obtained by linearization using SystemModelLinearize ("DocumentationExamples. Modeling. Generator" is the circuit given by the official routine). ...
0 votes
0 answers
42 views

Strange behavior with setting multiple values simultaneously

I'm having some strange behavior when trying to set multiple variables using {x,y,z} = {1,2,3}. When I enter "{a,b,c,a',b',c'} = {1,2,3,4,5,6}", it sets a,b,c,a',b',c' to 1,2,3,4,5,6 as ...
  • 101
0 votes
0 answers
24 views

Changing list of variables in text file

Imagine I have a .txt file as follows var1 = 2; rate = 10.3; power = -12; I want to use Mathematica to automatically update these values and rewrite the .txt file ...
  • 4,362
0 votes
0 answers
27 views

save function only for particular arguments to file

Define f[2] = 3 f[3] = 5 I know how to save the function to file: ...
  • 1
2 votes
2 answers
432 views

How can I make 10 variables from a for loop?

I used a for loop to make 4 variables: For[i = 0, i < 4, i++,bi=0] But when I write b0 or ...
  • 359
1 vote
1 answer
76 views

How to define functions using $Z_2$ coefficients and $Z_N$ variables, e.g, realizing $1+1=0$?

A minimal example is to realize the following: $x+x = (1+1)x = 0$, and $x^{N+1}y^{N+1}=xy$, where $N$ is a given positive integer.
  • 113
0 votes
0 answers
41 views

Reusing local variables through Reduce and ToRules

Problem: I am interested in solving a system of linear equations through Mathematica. In my current test scenario, I am having trouble using the Reduce function followed by the ToRules command. I ...
  • 101
0 votes
0 answers
44 views

Getting .wl file without appending global' before variable names

I have a .wl file created using mathematica that contains: list = {{a->4, b->5}} When I read it in using Get["file.wl"] it reads in as: ...
  • 55
2 votes
1 answer
121 views

Can you use superscripts as variable and function names?

I want to express the following function: $z^{(1)}=w^{(1)}a^{(0)}+b^{(1)}$ I have read in Mathematica documentation that Symbolize can be used to define variables ...
  • 323
1 vote
0 answers
70 views

Why =. is not clearing the value of a variable in this case? [closed]

I am reading "Mathematics and Algorithms" as part of the Wolfram Tutorial series. In "Values for symbols" section of the "Algebraic Calculations" chapter it is described ...
  • 323
6 votes
3 answers
148 views

How to define variables $a$,$b$,$c$,$d$ are all elements of set $\{2,3,5,7\}$?

I would appreciate it if somebody could help me with the following problem: I want to create a Wolfram Language expression that states that all $a$,$b$,$c$,$d$ variables are elements of the set $\{2,...
  • 259
5 votes
3 answers
160 views

Get the symbol name of the function's nth argument

I tried this: Plo[fun__] := SymbolName @ Part[List @@@ Unevaluated @@ {Hold[fun]}, {1}, 2] SetAttributes[Plo, HoldAll] On ...
0 votes
0 answers
67 views

How to define variables properly in mathematica, a variable with two name [duplicate]

I wanted to define a variable in the name "beam_frequency", this is quite possible in other programming languages like python and Matlab. How to define two pair variable name in Mathematica ...
2 votes
1 answer
87 views

Implement recursion one step at a time with a function of more than one variable

i am trying to implement a recursive difference equation step by step, by implementing rules, similar to Rojo's method in this thread: How can I evaluate only a single step of a recursive function? ...
  • 23
8 votes
1 answer
114 views

Very simple, unexpected Low Performance of set(=)

...
  • 3,561
0 votes
0 answers
40 views

How can I "map thread" similar notation definitions in one line?

In the past few days I have been dealing with different integral notation definitions made by myself. I have noticed several similar notation definitions with a common pattern, but currently I am only ...
  • 453
6 votes
1 answer
272 views

Is K is a function? [duplicate]

Some of the capitalized single letters are functions. Starting a fresh kernel and typing in the 24 capital letters, the following letters turn black since they are special functions, ...
  • 2,049
0 votes
1 answer
76 views

How to define prefix that can turn numeric?

I put these prefix in my init.m file. First I Unprotect all these symbols, set values and then ...
  • 2,822
0 votes
0 answers
73 views

Global assumption non zero

I would like to define globally an assumption stating that I have a nonzero real vector $v$. For now, I put : $Assumptions = Element[v,Vectors[{100},Reals]] but $v$ ...
  • 496
0 votes
0 answers
108 views

See variable as byte

I see variable v is occupying 112 bytes of my RAM. v = {3, 5, 7}; ByteCount[v] 112 Then how to see the content of the 112 bytes?...
  • 3,561
0 votes
1 answer
130 views

How to convert mathematica root expression to readable one? [duplicate]

I am trying to find out at what regions a function is monotonically decreasing. The function is a function of X and has two more variables epsilon and B with the constrains 0 < B, 0 <epsilon< ...
  • 35
0 votes
0 answers
36 views

How can I prevent functions and variables from being automatically cleared when I close Mathematica? [duplicate]

The following happens with every notebook I make: I define functions and variables. When I quit Mathematica and reopen the notebook, all of those definitions have been cleared. The functions and ...
2 votes
2 answers
201 views

Why is the parametric plot failing?

I tried running the following code but it doesnt seem to be working, it seems to be stuck on running. I think it's got something to do with the way I am defining functions with a variable integration ...
8 votes
0 answers
135 views

Defining a SparseArray functions in Mathematica 13

I am defining a sparse array as a function of argument x, i.e. f[x_] = SparseArray[{1->x}, {3}] In Mathematica 12 this works perfectly, I can pass arguments and ...
  • 81
0 votes
1 answer
59 views

Part of array as a blank variable [duplicate]

I have a little question. Let me define the function: f[k_]:=k So 'k' in the argument of 'f' is a blank variable. Is there a way to define a part of array as a ...
0 votes
1 answer
85 views

Errors appear after integration of an interpolating function

I have a little question about integration of an interpolating function. There is an error in assumptions of the integral. I have a function that was obtained with an interpolation method: ...
1 vote
0 answers
101 views

Plot implicit function with intermediate variable

Cross-posted in Wolfram Community. Here, I intend to plot a 3D picture of with two implicit functions where $x, y, t, \xi, \eta$, are variables. Of course, these variables can be constrained to ...
  • 103
1 vote
1 answer
112 views

Numerical integration in one variable, of a multivariable interpolation function

I create the following set of data: newmatrix = Flatten[Table[{t, v, new[t, v]}, {t, 0, 2 Pi, Pi/4}, {v, 0, 1, 0.01}], 1] where ...
1 vote
1 answer
82 views

expression evaluation for Compile[] too time consuming

I need to use Compile[] for a very large expression to be integrated. But for Compile[] the expression has to be evaluated, and this takes endless time. The expression is composed of several functions ...
  • 135
2 votes
2 answers
90 views

Problems with TagSet

I am new with TagSet and TagSetDelayed and I'm not understanding properly how they works. I introduced the following definition: ...
  • 141
0 votes
1 answer
51 views

Is always possible to define a numerical value using subscript?

In this code I defined some values using subscripts and it is not the first time I did this but strangely the code execution crashes. To follow the code. ...
3 votes
2 answers
175 views

Making a list of variables

Consider the following code, which give a Manipulate object that returns the "total" of a certain variable var 1 ...
  • 4,362
1 vote
2 answers
78 views

Remembering function definitions across sessions to avoid recalculation [duplicate]

I'm working with some large expressions and fourier transforms, which usually take a long time to compute. When I save my notebook with outputs to all my inputs, I'd like it to remember those ...
1 vote
0 answers
46 views

Defining a function expression [duplicate]

I'm sure this has been answered before, but imagine I have the following function ...
  • 4,362
0 votes
0 answers
47 views

Matching two lists and create variables

I have two lists of the same length. One of the lists has all the variable-names in it and the other one is a list of lists in which each list represents a value. I now want to automatically create as ...
2 votes
2 answers
99 views

Unexpected Behavior in `Sum[a + Subscript[a, 1], {a, 1, 2}]`

The simple command Sum[a + Subscript[a, 1], {a, 1, 2}] gives the unexpected result 4 + Subscript[2, 1] while what I want is $3+...
  • 1,009
7 votes
2 answers
276 views

Copy a function instead of referencing [duplicate]

Is there an option to let me assign the old function of f to g, without changing g when reassigning f? This piece of code describes my problem: ...
  • 563
3 votes
1 answer
86 views

Performing matrix tensor product and getting a sum of its negative entries

I am given a $3 \times 3$ matrix $M$, which only has real entries. Is there an efficient way to do the following two operations with $M$? For a given input $n$, compute the $n$-fold tensor product $M^...
2 votes
1 answer
96 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 ...

1
2 3 4 5
10