Questions tagged [assignment]

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

Filter by
Sorted by
Tagged with
0 votes
0 answers
19 views

How do I make a formatting rule for a pattern not containing a symbol to attach a rule to

I can define a formatting rule such as Format[ex[ls_List], TeXForm] := "grgr" But when I want to define such a formatting rule for a general patter, for ...
0 votes
1 answer
46 views

Problem with SetDelay [duplicate]

I am trying to do some calculations on very long and difficult equations. Ultimately, I want to create a function to NIntegrate my result, but I want to set it as SetDelay (to be evaluated after ...
1 vote
2 answers
48 views

Multiple assignments of items of a list [closed]

Suppose to have a list of items and two lists of indexes that are parametric and for example are: l={2,3,5,7,11,13,17} i1={3,4,7} i2={4,7,3} I need a clever code ...
5 votes
4 answers
598 views

How can I list the common elements of two lists?

The elements of both lists are given as A={9,5,9,3}, B={9,9,5,5} In this case, how can I list the list {9,5,9} of the common elements of the two lists? (The order does not matter.)
5 votes
4 answers
811 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 $...
5 votes
3 answers
325 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 ...
11 votes
3 answers
531 views

Part not behaving the way I expect it to

p = {{1, 0, 0}, {0, 1, 0}, {0, 1, 0}}; p[[All, 3]][[1 ;; 2]] = {1, 1}; p I want to replace the first two elements of the third column of a 3x3 identity matrix. ...
0 votes
0 answers
38 views

Formula to resolve max size of subset of set of strings

A set made up by strings, each string contains m characters, character is either ‘0’ or ‘1'. Now, what is the max size of the subset, which in the subset, each string has at least n characters differ ...
0 votes
0 answers
57 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 ...
0 votes
0 answers
32 views

How to find clear solution for iterative problem by condition $<v_k ,v_n>=0$ If $k!=n$

I want to find x[n] by v[n] values without x[n] in solution by iterative below problem: <...
0 votes
2 answers
77 views

Understanding SetDelayed, ":=" [closed]

Consider the example below, p = {1, 2, 3}; x = {x1,x2,x3}; fun[x_] := {{1, 0, 0}, {0, 1, 1}} . (p + x); fun2[x_] = {{1, 0, 0}, {0, 1, 1}} . (p + x); I expected <...
0 votes
1 answer
58 views

Delayed evaluation of nested functions

i am new to Mathematica. Here is the situation: I have a exponential function of n,t that I want to calculate integral over t ...
1 vote
2 answers
106 views

Replacing Kronecker delta times expression with the expression with inserted index

Consider the following symbolic expression: expr = f[a,b]*g[c,d]KroneckerDelta[a,m]KroneckerDelta[d,k] + KroneckerDelta[a,p]f[x,a]+const Could you please tell me ...
3 votes
1 answer
134 views

How to assign the following rule?

Consider the following object: function[x,a,b]. It is a symbol carrying one "coordinate" x and two indices a,b. I ...
5 votes
1 answer
219 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 ...
-2 votes
1 answer
163 views

How to assign values to x1+x2, x1x2? [closed]

x1 + x2 = -((2 a^2 k m)/(b^2 + a^2 k^2)) Enter the above content and an error prompt will pop up How to assign values to x1+x2, x1x2?
2 votes
3 answers
109 views

SetDelayed assignment not producing expected result when using ReplaceAll

In Mathematica, I am surprised that the following code does not do what I expect (what I expect is in comments after each evaluation). The problem seems to be due to the fact that when I define test ...
1 vote
3 answers
231 views

How can I permute two delayed variables?

Two variables with delayed expression are used for a random number generation: ...
1 vote
2 answers
151 views

Associating a string variable with a numeric variable

There is a translation operation from a numeric variable to a string variable: a[i_, j_] := Symbol["a" <> ToString[i] <> ToString[j]] How ...
0 votes
3 answers
117 views

Conflicting variables

So, I read a set of variables and respective values from a file and store them in a variable specs = {{"Type", "KP", "fp"}, {"LP1", 2, 2000}, {"Type", ...
3 votes
2 answers
205 views

About how to speed up in assignment

I would like to know if there is a way for increasing the speed of the following computation: I have a list, let's call it list, and another list of values, val. I ...
1 vote
0 answers
35 views

Hold around SetDelayed with Graphics [duplicate]

Minimum Working Example I've defined my own plot function, which does a lot of stuff to the inputs before passing it into the Graphics function. Because of that, I'...
0 votes
0 answers
56 views

Define a function using output of another function [duplicate]

I am away from my computer and therefore unable to experiment, but I am keen to scribble down a few Mathematica operations in note form ready for my return. So, forgive the simplistic question… Say I ...
1 vote
1 answer
33 views

Using plot on named expression and explicit expression produces different results

There is some strange behaviour in Mathematica which I don't understand. If you call a function like ContourPlot on two identical expressions (one a named expression, and the other the same expression ...
2 votes
1 answer
62 views

How to assign a value for specific Indeterminate expressions?

I wanted to form a list as follows j=1; Table[(i-1-j)^k, {i,2j+1}, {k,-j,j}] However, an error message occurred since the list included none positive powers of ...
0 votes
1 answer
66 views

Error: Invalid integration variable or limit(s) in {-6.28293,0,\[Pi]/2}

When i try to evaulate h at vaule (for example 0), i get a result. When i directly plot the output of h, it also works, but when ...
3 votes
4 answers
465 views

Define a delayed function depending on a global variable as though the variable's contents was pasted

Problem Say I previously defined a variable (maybe through some extensive calculation) thing = (a+x)y Then, I want to use that expression elsewhere. In general, I ...
2 votes
1 answer
289 views

How to assign a value to something inside a module globally? [closed]

Let's say I created a function that calculates something inside a module. How do I assign that result to a global value? Let's say I have this: ...
1 vote
0 answers
89 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 ...
0 votes
0 answers
35 views

ToExpression in nested Set/SetDelayed

Suppose we have the following definitions. ...
1 vote
1 answer
47 views

Manipulating the list with variables

I am trying to find the maximum element of the list for a given value of variable $c$. The example of the list is as follows: ...
0 votes
1 answer
59 views

Symbolic re-assignment of products

Suppose I have some symbolic tensors $X,Y$ and I want to assign X.Y into something else without specifying what $Y$ is. For example, I may want $Y$ to serve as ...
3 votes
1 answer
111 views

Problem with parametric integral with variable bounds

d[p_, B_] := \!\( \*SubsuperscriptBox[\(\[Integral]\), \(-B\), \(+B\)]\(Cos[ p\ x] \[DifferentialD]x\)\) Plot[d[x, 2], {x, -10, 10}, PlotRange -> Full] I ...
1 vote
0 answers
47 views

The assignment problem in Plot function [closed]

I used Mathematica to plot a system of equations: Plot[{y = 2 x - 3, y = x/2}, {x, -5, 5}, Axes -> True, AxesLabel -> {"x", "y"}, PlotLabels -> {"2x-y=3", "...
0 votes
0 answers
29 views

Set keeps RHS unevaluated when RHS is a Module variable [duplicate]

Consider the simple code ...
0 votes
0 answers
59 views

Assign different type of balls into output containers with constraints

The problem is to asssign all differend kind inputs to outputs. For example colored balls. On the input we can receive max 5 different type of colored balls any with amount. The amounts for the inputs ...
1 vote
1 answer
39 views

Delay evaluation of Chop until its argument has no symbols? (== has this behavior, Chop does not)

With Equal (==), if a and b are undefined symbols, a==b does not evaluate. This way we can ...
1 vote
0 answers
129 views

several actions inside If condition [closed]

Trying to write code with If, if it is correct to perform a number of actions. I am a beginner user in mathematica and not sure the form of writing are correct. What I'm asking in simple, this is the ...
6 votes
2 answers
93 views

Error message not reproduced at reevaluation, SetDelayed cache?

Mathematica v13.0: nr:=HoldForm@Evaluate@Function[t,x@t][] then evaluate ...
3 votes
4 answers
402 views

Defining a function iteratively without Mathematica getting stuck in a recursion loop

I have the following code: ...
0 votes
1 answer
91 views

NIntegrate seems to not recognize multiplication of Piecewise function and f[t_]:= function, Why?

Considering inputs: vti={0, 1.5, 2.4, 5.0675, 7.735, 10}; Vscc=1.5; PSA=0.025; f=0.6; m=10; I defined a function "pwtemp2", using "FC1" and &...
1 vote
0 answers
45 views

How can I access to the needed part of this expression? [duplicate]

I have defined a list like this: F[1][t] = ConstantArray[a1, 10] Now I want to assign to some of the elements the value 1; I ...
1 vote
0 answers
153 views

Extracting expressions from LHS of an assignment

I need to list all variables in a notebook containing several Set assignments, lhs=rhs, and equations, ...
0 votes
1 answer
55 views

Program works, but then fails when I write it inside Module [duplicate]

I'm new to Wolfram Language; I'm trying to get used to it by writing a bunch of code and programs, being one of them the algorithm for the bisection method. When I write the algorithm outside of a ...
3 votes
2 answers
154 views

How to make c[n_, x_, y_] := ToExpression["p" <> ToString[n]] = {x, y} work?

I am trying to do the following: c[n_, x_, y_] := ToExpression["p" <> ToString[n]] = {x, y} That is: Evaluating ...
0 votes
1 answer
133 views

Forcing mathematica not to substitute some terms in an expression

I have an expression c which should be defined before the function and a function f defined as follows: ...
0 votes
0 answers
117 views

Can't create matrix function of symbolic functions and assign values to elements

So I have a problem regarding the symbolic matrix value assignment. Say I create a matrix function as: P[t_]:= {{P1[t]}, {P2[t]}, {P3[t]}}; Then I want to assign ...
0 votes
0 answers
55 views

How to use Mathematica to return value from for-loop [duplicate]

I tried to use Mathematica to implement random generator. The pseudo code I use is as following: ...
0 votes
1 answer
80 views

any way to store the values of the controls of a Manipulate so that one can reuse them in the future excutions

I’m using Manipulate[] to adjust several parameters, which will eventually generate some figures. After I get the desired view, I’d like to store the set of control parameters so that I can reuse them ...
0 votes
0 answers
57 views

Block Behavior, but for Function Assignment instead of Variable Assignment

We can define a function using a variable b that does not appear as an argument, and then using Block, change the output of the ...

1
2 3 4 5 6