# Questions tagged [scoping]

Questions on Mathematica's scoping constructs (Block, Module, With, etc.)

412 questions
Filter by
Sorted by
Tagged with
44 views

### Facing problem using NSolve inside module [closed]

I have an equation called P, which is a determinant of the matrix R. This equation P is a function of ...
40 views

### Does passing patterns between packages alter their name unbeknownst to the user? [duplicate]

This question is a partial followup to my previous question. Mainly, after using With to inject the proper argument in the function at the rhs of ...
45 views

### How can I make parameters set by an array of buttons known to other quantities in my model?

With help from @m_goldberg, I developed the following model: ...
56 views

### Handling a list of variable assignments to be used with With [duplicate]

Is there a way to use With as follows? variables := {a = 2, b = 3}; With[variables, a^b] Desired output ...
35 views

### Mathematica Function Taxicab Numbers [duplicate]

I have spent days trying to compile this code and I cannot generate a list of taxicab numbers for the Hardy-Ramanujan Theory. Here is the module I wrote earlier: ...
20 views

### Referencing a control from within a module

Below is a simple Manipulate that references a module via a button, which resets a slider and value. I would like to reference and reset the slider control for the slider "n" from within the module "...
35 views

### Problem in solving a trancedental equation which is embedded in module

I have written a small program to compute the resonance frequency, for that I am solving a transcendental equation, which comes from the determinant of the matrix ...
51 views

### Turning an equation into a function in a module

I have defined a function like this: f[q_] := Module[{g}, g[x_] := Evaluate[q]; ... ] I am calling the function like this: ...
30 views

### For different value of input module is giving same result

I have a simple module written to extract a certain shape for a certain value of ω, but I am getting the same result for different input values into the module. 1.mode and mode looks exactly ...
115 views

### Memory leak with FindMaximum/Minimum inside of Module

This is my first question here. I have to solve coupled first order ODE-s and find the maximum of a function which depends on the solution of the ODE. I have to do this calculation in large quantities,...
53 views

### Is it possible to create complicated packages from modules which work fine by copy paste? — A counterexample [duplicate]

Here is a module which constructs essentially several functions in a chain [Phi], sct, ks, WE, G: ...
71 views

### Facing error while solving a determinants with the use of NSolve inside module

I have written a small program to find the natural frequencies of some system using an energy approach. v1 and t1 are the potentials and kinetic energy of the beam. v2 and t2 are the potentials and ...
102 views

### Transferring a function between two modules in a package

I have a first module which outputs as forth output a function G I want to transfer to another module. The specific function is ...
80 views

### Sum of n sums, Permutations of the indices, how to write them in Mathematica?

I was wondering how to write a function $F (r, q, n, f)$ in Mathematica, defined in this way: F(r,q,n,f):=\sum_{i_0=1}^q f(i_0) \Biggl(\sum_{i_1=i_0+1}^{q+1} f(i_1)\biggl(\sum_{i_2=i_1+1}^{q+2} ...
30 views

### Can I still use global variables when I choose the default context to be the cell group?

To avoid accidentally reuse the same variables in different sections of my notebook, I go to Evaluation menu and choose Notebook's default context > Unique to each cell group. But sometimes I do want ...
117 views

### Best practice with Return in Module or Block

I am a bit confused on the use of Return in either Block or Module when defining a custom ...
160 views

### Using With[…] with a list specification as a variable [duplicate]

If you have some defined function, say f[a_, b_ c_, x], one can initialize this by using With[...] as ...
74 views

### Scoping construct for dependent constants

I sometimes want to write a function which needs to apply a bunch of transformations that are not functions of a single parameter only: ...
117 views

### function evaluation - I don't get it

this function returns Pi/4 for a[1,4] In[...]:= a[r_, n_] := Module[{an = Pi/n, h = r Cos[an], w = 2 r Sin[an]}, an]; a[1, 4] Out[...]= Pi/4 so the kernel ...
109 views

33 views

### Evaluation of Extract and use the result in a Sum

I am experiencing a problem in the evaluation of a sum. I hope that someone can help me, I am not an expert Mathematica programmer. I'm posting just the portion of code that gives problems, I know ...
144 views

### Scoping of pattern variables [duplicate]

I have run into a problematic behavior, and then came to find that it is a "possible issue" called out in the documentation, but I guess I am just baffled that this IS an issue, and am wondering why. ...
131 views

### Can I bake my own PI using your Wolfram language oven and prebuilt utensils? [closed]

How might I override the value of the Greek letter PI within various builtin language functions in the Wolfram language? Specifically and without having to reinvent the wheel or code equivalent ...
71 views

### How to define a function inside a module through Evaluate [duplicate]

I am trying to define a function inside a module as following ...
47 views

### Symbol created in Module not seen outside of Module scope [duplicate]

I am using a function defined with a Module[]. In the Module I am creating a new variable name using a ...
55 views

### ConditionalExpression still resulting from Assuming a Module's local variables

I have a memoizing, recursive function whose MWE looks like this (the two fake inputs/ICs are from 'K' and 'Bfun2', the latter just a quick way to check the results coming out of the Residue.: ...
85 views

### How do I localize changes to a variable inside a Do-loop?

I want to change the increment value inside the do loop . But i dont know why it remains for the first declared value? ...
105 views

### MostOccuringWeekdays Wolfram Challenge [closed]

I am working this challenge from Wolfram Challenge. I believe that I have solved the problem with the following code (note it is not very efficient - I am new to Mathematica!) ...
64 views

### Module - Symbols out of scope of lexical scoping

The Problem Consider the following code (1): In:= x = 2; Module[{x, y}, y[x_] = x; y ] Out= 2 I expected the answer ...
220 views

### What is wrong with Module? or me? [closed]

The following code does not give me an answer. It looks all is working when each command inside Module is individually run. But ...