Skip to main content

All Questions

Filter by
Sorted by
Tagged with
1 vote
2 answers
72 views

How to extract manipulated indexed variables from Manipulate

I am struggling with getting values of variables that are manipulated with Manipulate: The code: ...
atapaka's user avatar
  • 4,036
1 vote
1 answer
63 views

Variable replacement not working in ParallelTable

The following code produces different results using Table and ParallelTable. K and ...
xiaohuamao's user avatar
  • 4,758
0 votes
0 answers
165 views

Using the for loop in the Module function

Good afternoon, I need some help. I have compiled a function that calculates the flight of the ball, step by step I made an analytical solution first, then a numerical one. But in numerical it is not ...
vic165's user avatar
  • 101
2 votes
1 answer
47 views

Why are the inputs not being applied to the function in this MWE?

Consider the following MWE ...
user106860's user avatar
9 votes
1 answer
156 views

How to define a version of Table[] which localizes iteration variable by Module[]?

For reusable code it's good practice to use Module[] to localize iteration variables used by Table[], as explained by this post. ...
felix's user avatar
  • 569
2 votes
1 answer
136 views

How to partition $[0,1]$ into $m$ equal sub-intervals and count the number of sub-intervals that intersect with my cantor set?

Suppose I define my cantor set as ...
Arbuja's user avatar
  • 121
9 votes
1 answer
394 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 ...
მამუკა ჯიბლაძე's user avatar
1 vote
1 answer
63 views

How to set same Variables with different Values [closed]

I have a pipe with different insulation sections and a fluid flowing through. I need to calculate the fluid Temperature at the end of every section, to estimate the temperature for the next section. I ...
user700676's user avatar
0 votes
1 answer
109 views

How to use module to assign functions to a set of imported text files?

I have a lot of text files in my folder (in this example I'm using only 8). I am trying to import all of them and then do calculation on each individual file; I want to use the same notebook without ...
Erfi's user avatar
  • 121
1 vote
2 answers
268 views

function fails to use local variable when it is called inside a Module

I have these two functions fun and microstep.Fun makes use of a Module construct within which I define the ...
Alucard's user avatar
  • 2,709
2 votes
2 answers
293 views

Table and evaluation order

I thought Table should not evaluate the inner code until it inserts the value. I'm confused by test1[3]="a"; test2[4]="b"; Table[DownValues[i],{i,{test1,test2}}] ...
Kvothe's user avatar
  • 4,781
0 votes
1 answer
59 views

Error when calculating more than 1 input

I'm trying to solve a problem where I can't do more than 1 calculation inside a Module here. I have a list of numbers where ...
Zen 禅's user avatar
  • 23
2 votes
1 answer
1k views

A function which performs multiple steps

I'm trying to figure out how I can define a function which takes an input, performs an operation on it, then produces a table from the result. For example, I have a function ...
Kai's user avatar
  • 2,139
4 votes
1 answer
135 views

Using Position[] inside a Module

I have a dataset with missing or wrong values. A module should replace those values so that the dataset length is preserved. For identifying the positions to be replaced I use ...
Hargrot's user avatar
  • 195
1 vote
1 answer
282 views

Iterator order breaks Table

Evaluating the following Table expression ...
user avatar
0 votes
0 answers
71 views

Error in storing the output of a module (subroutine) into an array

For a physics application, I have to compute components of a rank-4 tensor, the Riemann tensor. I do this using a module (subroutine) which looks like this ...
leastaction's user avatar
0 votes
2 answers
422 views

Using recursion to find the trace of gamma matrices

All you need to know about the gamma matrices for this problem is that there are four of them, $\gamma_{\mu}$ with $\mu = 0, 1, 2, 3$, and that the trace of the product of n gamma matrices (n even) ...
user45875's user avatar
2 votes
0 answers
136 views

How does Table behave differently? [closed]

I have some functions, that I cannot break down to a reasonable MWE, so I'm going to try for an abstract question without providing the code. If need be, I'll include the extra code. I have some ...
bjorne's user avatar
  • 569
3 votes
2 answers
2k views

Can you unpack a list of values into variables in a With expression?

For instance, if I am trying to draw a graph with 5 vertices labeled a through e, and I want to draw edges connecting a and b, a and c, a and d, a and e, b and c, b and d, and c and e, I would run the ...
ericmarkmartin's user avatar
11 votes
2 answers
264 views

How to correctly implement in a new function the scoping behavior of Table, Sum and other commands that use Block to localize iterators?

It is documented that "Block is automatically used to localize values of iterators in iteration constructs such as Do, Sum, and Table." Therefore the dummy index (iterator) in a Sum is shielded ...
MaTECmatica's user avatar
1 vote
1 answer
1k views

Change input variable in a function [duplicate]

I'd like to write a function, that would take a matrix as an input parameter and would change it by multiplying one of its rows by a factor. I try to do it in the following way: ...
user1541776's user avatar
1 vote
2 answers
246 views

`Slot` (#) interfering with evaluation

In the following I am using one function makeFunc to assemble two functions a[t] and b[t] to ...
Andy Mobley's user avatar
0 votes
1 answer
866 views

Passing lists to functions in a manner that works like pass-by-reference in other languages?

Is it possible to use a list as a variable, i.e., to pass it by reference to a function? In particular, I have a two-dimensional array and a function to get one element specified by its position: <...
Jo Mo's user avatar
  • 175
9 votes
3 answers
888 views

How do I avoid scoping collisions of iterator variables?

Yesterday I had an issue that kept for quite a while. My code wasn't producing the right results. Now I know why and I am wondering how to avoid the issue in future. Consider the following code. <...
Volker's user avatar
  • 950
1 vote
3 answers
147 views

Mathematica loop code not behaving as expected

...
March Ho's user avatar
  • 649