Questions tagged [assignment]

For questions relating to assignments to symbols, patterns, or expressions.

Filter by
Sorted by
Tagged with
0
votes
3answers
55 views

Assign value to the symbol returned by function

Ok, so here is example code: Clear[p, flag, k]; p = 2; k = 1; flag = True; If[flag, p, k] = 0; p After that I get the message ...
3
votes
2answers
106 views

Set value in a list at given position

Consider r = Array[Total[{##}] &, {3, 3}] (*{{2, 3, 4}, {3, 4, 5}, {4, 5, 6}}*) pos = {{1, 1}, {2, 2}}; vals={100,200} This ...
0
votes
2answers
67 views

Using a list as arguments in a function

This might sound a little silly question but I cannot get my code work. Here is the problem: I have quite a few lists of data which are basically beam profiles. I am using ...
0
votes
0answers
25 views

Setting paths of packages once and for all

My question is quite elementary: Each time that I want to load an external package package.m I have to run: ...
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 ...
1
vote
2answers
35 views

How can I use Part Assignment to change sublists into other sublists (without changing levels)?

Here's a 5x5 grid. Using predefined starting points, I'd like to change some sublists into something else (e.g., the values for a color, "drawing an opaque box"). ...
3
votes
3answers
236 views

Changing value of specific element in an array. (Converting code from MATLAB to Mathematica)

Can we change the value of a specific element of an array in Mathematica? Basically, I have the following given MATLAB script which writes a big 3N-by-3N matrix $h$ by combining two 3-by-3 matrices $...
1
vote
1answer
47 views

Scan and Set over multi-dimensional data

Suppose I have the following: Table[x[i,j] = f[i,j], {i,1,10},{j,1,10}]; I want to set variables x[i,j] to have value ...
1
vote
1answer
35 views

Default Options not working in user-defined function for SymbolName

Abstract I have a function objectName[symbol] that returns the SymbolName as both a standalone function or when nested inside ...
1
vote
1answer
32 views

Setting a function equal to another function then Clearing the latter

I have a loop in which several values of a function are computed, depending on the values for that function that were computed in the previous iteration of the loop. This could be implemented ...
1
vote
1answer
40 views

Set: in part assignment is not a symbol [closed]

This is probably a basic question but I am new to Mathematica, so please help me out here. I have the following piece of code: ...
2
votes
2answers
48 views

Cannot understand meaning of “identical”

This came up in the context of plotting solutions to NDSolve, but I've reduced it to the following issue. This really has me scratching my head. ...
4
votes
2answers
80 views

Using pure functions to assign a value to variable depending on whether it has been defined already

Let's say I want to assign to a variable the value $2020$ if it has not already been defined and do nothing if it has. In short, for a variable $a$, I want to achieve the functionality of ...
6
votes
4answers
184 views

Assigning a string to variables names

I have the list n1 = {{REL1, "REL.csv"}, {RAND1, "RAND.csv\"}}. That is {{variable name, string}, {name, string}}. I want ...
2
votes
1answer
37 views

Problem with superscript

I would like to know if there is option to make such scrpits like in this picture below. Is option to put letter instead of a *?
0
votes
0answers
4 views

Assigning a solution to variables [duplicate]

I have solved my solution and it has been appeared, it is C1, C2, C3, C4 but when I call C1 again (%13), program shows me that C1,... is not assigned. How can I reapair that ?
4
votes
1answer
81 views

Why the difference in performance? Array vs List and `Delete` vs `Nothing`

In a previous question I was warned against the use of Nothing to delete elements from a list, and rather use Delete. Being of ...
7
votes
1answer
98 views

How would you explain Nothing[] weirdness? [duplicate]

I would like to use Nothing[] to make some elements of a list invisible. (The intended use is to remove a few unwanted points from a ...
9
votes
1answer
127 views

Why Optional in Set is not held by the HoldFirst attribute?

When evaluatingf[x_:x0] := x, x0 will be evaluated, regardless of the HoldAll attribute of <...
4
votes
2answers
174 views

Using module to define a function that calls another function: Should i use set-delayed (:=) or set (=)

Suppose that I have a function f[x_,y_,z_]=x*y*z and now suppose I want to consider a specific application where z is a ...
1
vote
0answers
67 views

What does a single vertical bar mean in ConditionalExpression? [closed]

I got the condition below as part of a ConditionalExpression. Those single vertical bars before and after $\frac{1}{k1}$ appear to be an absolute value but I don't ...
0
votes
2answers
107 views

Assign FindRoot output vector to a vector instead of element by element

Using FindRoot to solve a multivariate equation system, assigning the output to variables one by one works, but assigning the output vector to a vector gives the ...
0
votes
0answers
25 views

Performing operations on LHS of assignment [duplicate]

Is it possible to first perform an operation on LHS of the = symbol, evaluate that, and then assign the RHS to the new LHS as usual? The following shows the most ...
1
vote
2answers
63 views

Assigning values to multiple variables from a list

I have a solution of the following form: $F(x)= \\ \qquad c+(x_0+x_1+x_2+\ldots +x_n)- \\ \qquad (x_0\,\log(x_0+\sqrt{x_0})+x_1\,\log(x_1+\sqrt{x_1})+x_2\,\log(x_2+\sqrt{x_2})+\ldots +x_n\,\log(x_n+\...
5
votes
1answer
103 views

Setting options of object after defining it

Is it possible to edit the options of an object like Plot or Graphics after I store it as a variable? For example, consider the ...
1
vote
2answers
36 views

Assign numerical values to symbolic variables in a vector inside a do loop

I have vector k = {k1, k2, k3, k4, k5, k6}. I would like to assign numerical values to the elements of k in each step of a <...
0
votes
1answer
59 views

How to turn a matrix into a 'function'? [duplicate]

I have some codes to turn a set of equations into a matrix. Suppose the matrix Lis expressed in terms of variables $\epsilon$, $K$, $M$, and I want to make a ...
3
votes
2answers
175 views

What is the point of tagset /:? [duplicate]

I'm teaching myself Mathematica and came across tagset. So I followed the example in the link, but seem to be missing the point. All of the below give me the same answer after assignment: that ...
1
vote
1answer
49 views

TagSetDelayed for spotting zero derivatives

I am trying to implement my own differential operator, d[arg_, var_], that computes the derivative of arg w.r.t. ...
1
vote
1answer
46 views

Part Assignment of variables with argument

I do not really understand why this: a = {1, 2, 3}; a[[1]] = 3; a {3,2,3} works as desired, but this does not: ...
2
votes
1answer
38 views

SetDelayed error for Derivative rule

Having a delayed assignment of the form Derivative[1][f][x_] := HoldForm[f[x]] works. But if there is a delayed assignment for f as in ...
0
votes
0answers
23 views

Approximating the density of an arbitrary set using an arbitrary Folner Sequence of its superset [duplicate]

How do we use Programming to approximate this limit where is the density of in , is the Folner Sequence of , is an interval with , and . For more information, click on this link (replace G,X,i,g ...
8
votes
1answer
140 views

Error Message when nothing should be evaluated

When I try to define this simple function getCoeff[SeriesData[_, _, coeff_, _, _, _]] := coeff[[2]] I get an error: ...
1
vote
1answer
76 views

ContourPlot a list of equations generated by the Table command

The first command below produces proper contour lines while the second command produces an empty plot. I would think that the two commands should produce the same output. What's going on? ContourPlot[...
0
votes
0answers
27 views

Defining a function from an evaluated function stored in a variable

I have the evaluation of a function b, stored in appo. Now I want to define a new function f ...
0
votes
2answers
100 views

Monte Carlo Method [duplicate]

How do you use a Monte Carlo method to approximate the area enclosed by the circle.
2
votes
0answers
35 views

Mathematica: Remove argument from object with flat attribute

I have an object in mathematica with the attributes Flat and OneIdentity. I also defined the following substitutions: ...
3
votes
1answer
61 views

Combining `With`, `If` and SetDelayed

I just noticed that With[{x = 1}, If[x == 0, 0, 1]] returns 1 (as I expected) but ...
1
vote
1answer
45 views

Drop-down menu to globally change definition of a function `t[x]`?

If have a function t[x_] which is used extensively in a long notebook, but which has a variety of definitions, and which is used in a variety of ways. I'm looking ...
0
votes
2answers
30 views

How to select certain numbers to assign a new value and others still keep same

For an array TestA={15,12,5,8,6}, I want to change the value of number greater than 10 into 0, as TestB={0,0,5,8,6}. When using "Select" command, I will lose some numbers. Thanks.
1
vote
1answer
43 views

Vector shape and Dimensions

I think I have not understood clearly the difference between dimension and shape. I want to construct a vector remembering recurrence of the type : ...
2
votes
0answers
32 views

Programmatically Inject Logical Vector into Manipulate Checkboxes or Vice-Versa

I am building a large Manipulate application with about 50-60 checkboxes through which the user can select entities to be drawn on a main canvas. The main drawing routine, called from within ...
1
vote
2answers
79 views

Error in Assignment

I want to create a matrix with each element updated as per the formula, whose inputs are dependent on the location of element in the matrix. ...
1
vote
0answers
31 views

Un-assign MenuCommandKey

In my StyleSheet, I would like to assign to the environment Subchapter the Key Alt+2 (via MenuCommandKey. However, this is ...
1
vote
2answers
99 views

How to assign output of `Last@Reap` to a variable? [closed]

I would like to define a variable that equals the solution of a numerical equation. Usually something like smax=zmax/.FindRoot[Exp[-zmax/2]==2,{zmax,0}] would work. ...
1
vote
1answer
51 views

Why does it fail to assign values to variable in Grid? [closed]

I have a grid such as the following, and want to assign the values in the second row to the variable in the first row, but it always fail, can you provide a solution? Thank you! ...
0
votes
1answer
46 views

I am asserting a variable in Mathematica as Real yet it is not implementing it!

Element[\[Theta], Reals]; Ga = g; Gb = g*Exp[I*\[Theta]]; {{Conjugate[Gb], Ga}, {Ga, Gb}} I have a code as such for a matrix as given above. as ...
0
votes
0answers
209 views

Assign a Derivate to a new fuction variable

I'm having a new problem. I'm trying to create a new function from a Derivate of another function, but i'm can't getting it. Someone could help me? I'm thinking that is something in the syntax of the ...
4
votes
4answers
150 views

Is it possible to create lookups on temporary symbols that still allow the symbols to be automatically removed?

Is there some way to create lookups keyed on Temporary symbols that somehow avoid the referencing of the Temporary symbols, ...
1
vote
2answers
31 views

A question about a replacement of element of set

To begin with, I'm a poor English speaker, which means it would be hard to read to natives... I was trying to memorize mRNA codons with mathematica. ...

1
2 3 4 5