Questions tagged [scoping]
Questions on Mathematica's scoping constructs (Block, Module, With, etc.)
480
questions
0
votes
0answers
55 views
Check if elements of a given list are coprime [closed]
I'm trying to implement Chinese Remainder theorem and so far I have this.
...
1
vote
1answer
49 views
Using With[] vs. Using a Pure Function for Constants
There are many cases where I am conflicted over using With[] versus using pure functions when dealing with constants, knowing the output is the same either way. For ...
0
votes
0answers
28 views
Numerical errors in compiled function involving real and complex numbers as output
I am trying to use the Compile command in Mathematica to reduce the computation time because of its fast execution within Mathematica and ability to use the ...
1
vote
1answer
37 views
How to Show Velocity and Time Measurements in Manipulate (Wolfram Demonstrations)
I am working with a Wolfram Demonstration that uses the Manipulate function (which I am not yet familiar with).
The code is
...
0
votes
1answer
29 views
How can I create a PasteButton that changes its “contents” dynamically?
I'm trying to make a units palette to help with my various engineering courses. I thought about creating a "meta-palette" of sorts, maybe one that changes on the fly, or one where I can ...
0
votes
0answers
28 views
Display more outputs inside Module and Which
As it can be seen in the following piece of code, i would like to display more outputs which are inside a Module, part of a function definition. In turn this is ...
0
votes
1answer
67 views
Passing symbols, variables and defining functions within functions
Moderators state: “You will be brief and straight to the point”, and so do I.
All codes test whether a polynomial is even or odd, using different approaches.
This works:
...
1
vote
1answer
45 views
Unique symbol for parallel kernels
For each kernel, a unique symbol can be generated with Unique[]. However, since it's basically defined by the growing ...
4
votes
0answers
40 views
`Function` does something bizarre with formal parameters
I think this may overlap with existing questions, including one I asked years ago, but I'm not sure how, because the behavior I'm seeing is confusing enough I can't even really describe it except to ...
1
vote
0answers
52 views
Autoloading MaTeX` and Rubi` via DeclarePackage[] in the user init.m does not work
Former question: Autoloading and adding code to a package in the user init.m
I am using MaTeX, and I found the updateMaTeX[] function] at the GitHub repo.
I tried ...
4
votes
0answers
89 views
DynamicModule Error when assigning Nothing to variable
Assigning Nothing to a variable inside Module works as expected:
...
2
votes
0answers
37 views
Strange Replace problem within RuleDelayed within function [duplicate]
I've run into a strange anomaly with Replace when it is performed inside the first argument of RuleDelayed within a function ...
0
votes
1answer
80 views
Combination of Block and With - Unexpected results
I'm trying to use Block to prevent a function from executing. In this example, the function I'm trying to block will simply be ...
6
votes
1answer
82 views
Context Manipulation within Scoping Constructs
In the following the full context form of Test is not required as "Aaa`" is added to ...
1
vote
1answer
35 views
Strange behaviour of SubValues of a definition in a context
First we define a context:
Begin["Ctx`"];
ClearAll[f];
f[m_][n_] := n // (Range /* Append[m]);
End[];
We can check that
...
6
votes
1answer
69 views
Compile - Optimization of function calls - does it matter?
I was surprised to see that, in the results of CompilePrint for a function made with Compile, calls to ...
2
votes
2answers
183 views
Wolfram modules returning functions
I am trying to get a With / Module pair to return a set of functions.
...
4
votes
1answer
106 views
Scoping problem? [duplicate]
Why
(f[1, 0] /. {x : 0 | 1 :> 1 - x}) -> 0
returns (expectedly) f[0, 1] -> 0, while
...
4
votes
2answers
61 views
Functions within modules within Compile
I've noticed that if I try to define a Function within a Module within Compile, I get errors ...
2
votes
1answer
69 views
More control over plotstyle in TwoAxisListPlot
I don't understand how to modify the ColorData in the mapIndexed for the code from another post found here and is copied below for reference. What I want to do is control the color of each trace as ...
1
vote
0answers
34 views
How to Inherit Arrowheds size?
I'm trying to write a Module that produces some arrows with custom Arrowhead shapes. However, I want the code external to the <...
0
votes
0answers
29 views
Replace the output of a module containing local variables by their actual value
I want to construct a function as the output of a Module, but I obtain the local variables as part of the output. This is a problem when I try to construct many of these functions in a parallel table, ...
2
votes
2answers
60 views
Implement Table and Sum replacements scoped with Module
Functions like Table and Sum are scoped with Block, rather than ...
3
votes
3answers
107 views
Memory isolation autochecker
I'm working on a project in which I'm putting everything in modules to make sure I can run multiple instances without them interfering with each other, however I'd like to have it automatically let me ...
1
vote
2answers
69 views
Manipulate not showing the four curves I want to manipulate
I've tried to display four functions in a single plot without success and I don't know how I should change my code in order to see the function. Indeed when I run the command I just see the axises but ...
1
vote
0answers
45 views
Why is my code for counting function calls not working?
I am tryin to calculate how many calls to a function my code is using.
...
-1
votes
1answer
63 views
How can I prevent my special symbols to conflict with other global symbols?
I am building a tool to manipulate Feynman diagrams and depict them using the Graph functionality. A diagram might have the following syntax
...
0
votes
1answer
47 views
Getting error messages form Set while trying to implement the bisection method with a For-loop [duplicate]
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 ...
2
votes
1answer
67 views
Why some variables get substituted and others don't
I was running into some trouble with my math and I whittled it down to this nugget:
...
3
votes
2answers
144 views
How to use a list of indexes as a variables inside a Module?
This is a trivial function, just to show that Module does not recognize the list generated by Table.
...
0
votes
0answers
40 views
Locally remove definition of function
Consider the following code
g[x_]:=x^2
f[x_]:=2*g[x]
f[x] (* returns 2 x^2*)
test[x_]:=Module[{g},f[x]]
test[x] (* returns 2 x^2 as well*)
What I would like to ...
3
votes
1answer
67 views
Problem reusing Dynamic variables illustrated by synchronized Panes code
Suppose I have several plots that represent different views of a common set of time sequence data but each Plot contains too much data (all of which I want ...
0
votes
1answer
65 views
2
votes
1answer
42 views
How to “Hold” variables assigned value inside DSolve?
Consider the following ODE:
a = 0.8; b = 8;
v = DSolveValue[{
u[x] == a*(b* u'[x] + u''[x]),
u[4.925] == 4,
u'[4.925] == 0.625
}, u[x], x]
which gives ...
1
vote
0answers
44 views
Recursiveness in backtracking algorithm
In order to familiarise with using basic algorithms in Mathematica, I am coding a sudoku solver using a backtracking algorithm. I am treating the sudoku itself as an association (I want to learn to ...
3
votes
1answer
45 views
How to use two separate colours for two lines in a single 'Plot' within the 'With' command?
'''With[{k = {1, 10}}, Plot[k*x^2, {x, 0, 1}]]'''
I want to use two separate colours for two k values. How to do that? Thanks in advance.
1
vote
1answer
42 views
Returning (not displaying) graphics from a Module
I want to create a Module which puts several parametric surfaces together as one object. For example, say I want to create a module which returns a cylinder that has a top, bottom, and cylindrical &...
1
vote
1answer
86 views
Is it a good idea to unprotect standard commands?
I often see in code by other people some standard functions like Sum, NonCommutativeMultiply etc get unprotected, supplemented ...
2
votes
3answers
83 views
Strange Behavior of Compile[] inside With[]
Consider, in the examples below, the difference between defining $n$ as a global variable or as an argument to function comp[], which includes a compiled function ...
0
votes
1answer
54 views
Keep irrelevant variables outside function arguments
I want to define several functions of variables x,y say
...
0
votes
0answers
60 views
NDSolve and NIntegrate with parameters
I have a problem with a numeric computation. I should solve a numeric ODE and the rhs is a numeric parametric function that I find with several NIntegrate. I'd like ...
2
votes
1answer
30 views
Return exact solution in one variable from Series as an option
I have a module which expands many functions, depending on expansion order input parameters. Here's an MRE:
...
2
votes
1answer
59 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
...
0
votes
1answer
41 views
Why is my dynamic slider no longer working?
This used to work but I accidentally made some unrecoverable edits and it stopped displaying. It supposed to adjust the background color of the current notebook. Please have a look and see what is ...
2
votes
2answers
152 views
Bad behavior of Block function [closed]
It seems that there is an extreme bug in the Block function that has puzzled me a lot today.
Below I give two code samples. In the first one can see a bug. In the second one can see that this bug is ...
1
vote
0answers
42 views
why does dataset not preserve its associations in Module[]? [closed]
Hello I am perplexed as to why a dataset, ds1 in this example, does not return the association with index and content in it.
...
0
votes
1answer
59 views
Blank plot is returned when trying to use Manipulate[Plot3D…] on the output function of NDSolve
I am currently trying to solve a transient cylindrical diffusion problem with space variable (r,z). Using NDSolve, I get a certain Interpolation function but I can't plot it no matter what I try.
...
11
votes
1answer
202 views
Proper Syntax highlighting for multi-argument With?
For the case of Block and Module one can choose to define values in the body for the variable names being scoped. So there is no ...
1
vote
0answers
51 views
Using `Block` with Conditions `/;`
I would like Block to run conditionally. I understand how to do one condition, but what about an AND operation?
e.g
...
1
vote
0answers
36 views
How to return a variable name and value from within a self-contained function block?
Abstract: I have viewed other solutions on StackExchange but none actually address using a fully self-contained function to return name and value of a variable. The only function that works requires ...