# Questions tagged [procedural-programming]

217 questions
Filter by
Sorted by
Tagged with
107 views

### How to put a loop in a loop

I am doing some work with black-scholes. As commented within my code, I need my while loop to run 100 times. I am not sure if the best way to do this is with a nested argument or placing a for loop or ...
47 views

### Replacing the input with output

I have the following code, ...
75 views

### Writing code to produce continued fractions

I have been trying to create a continuing fraction to help prove the theory about any rational number: a/b being able to be written as a continued fraction where the remainders found in the Euclidean ...
50 views

### Variables for multiple data files plotting using same Mathematica notebook

I am not an expert in mathematica, I have this following code. As you see I import a text file under the name "MyPoint1", plot with "pAll" then I do some more calculation with more variables and ...
58 views

### For-loop not indexing correctly [closed]

I have a question. Why does my result start with J = 2? I write another loop but it start 1 i confused-i need help ...
73 views

### Defining list of new variables at once (in a loop?)

I have a list of solutions Subscript[x, 1][t], i = 1,...,n (n given). I would like to use these variables to define new variables such as: ...
66 views

### Find the position of all the prime numbers up to a given number

I want Mathematica code the does what the following pseudocode does. ...
317 views

### How can I solve the Ramanujan problem by using Wolfram language? [closed]

The problem like this: find all integers n, 1 ≤ n ≤ 10, 000 such that n is the sum of two cubes of positive integers in two different ways. I want to solve the problem as a procedure in mathematica.
38 views

### How to solve this with Nest?

Just get {10} from code below. jason[x_] := Module[{}, {b = 1}; b = b*Nest[# + 1 &, 1, x]; b] jason /@ Table[i, {i, 1, 10}] This gets it right with Do ...
70 views

### Looping routine to evaluate a recursively defined function

I'd like to do a calculation which is basically a looping routine to evaluate a recursively defined function. For example: ...
95 views

### Creating a loop that gives first value that is false/true

My question is, if there is a command/function that gives me the first value for which an expression becomes false?! For a simulation of several rounds of the game battleships(ger. Schiffe versenken) ...
75 views

### How to iteratively (or most efficiently) create such list?

Update A very crude attemp ...
113 views

### Extract outputs from a WHILE loop in a table format

How can I convert my multiple outputs of a while loop in a table form and save it for later use. Here is a sample code: ...
158 views

### How is the best way to integrate using loops

I'm using Mathematica, and I want to integrate a function f[wr] in wr using some method that works with a Table/Do/For in the variable wr. I tried to use something like the Riemann's sum, to evaluate ...
85 views

### How can I plot these straight lines in a picture?

How can I plot these straight lines in a picture? ...
354 views

### How to use AppendTo in a While loop? [closed]

I am trying to code a while loop that uses AppendTo to append the loop variable to an empty list. ...
107 views

### Changing iteration variable in Do loop

I want to generate random positive hermitian matrices, I start with such a code ...
33 views

### Optimization of Do loop with multiple variables

I am pretty new to Mathematica and I would like to optimize a Do loop with multiple variables that I have. I have three lists of three elements each, with the condition that the first element must ...
55 views

### Why do I not see any results from my For-loop? [closed]

I am sure I am missing something trivial :-( Still any help is welcome. ...
86 views

### Numerical Fredholm integration using loop

I have a code line having two Do loops, one within other. In certain situation arising within inner loop, I want the outer Do ...
84 views

### For- loop which can reuse updated values [closed]

Eout = E^x ; For[kz = 1, kz < 4, kz++, Print[Eout1[kz] = Eout]; Print[kz]] The output is E^x 1 E^x 2 E^x 3 But what ...
76 views

### how to run a specific cell in a notebook from another notebook

I have a long Mathematica code in a notebook, denoted by NB1. Since it is a very long code, and I need only some of the outputs from NB1 to be used in another ...
55 views

### What techniques have you employed to avoid loop in Mathematica? [duplicate]

It appears to me that loop in mathematica is very slow (compared with matlab). Since many people still use mathematica to finish their work, there must be some techniques to bypass this problem. ...
160 views

### For loop for two variable at the same time

Can I use for loop for two variables as example show below at the same time? for (int x = 0, y = 0; x < 10 && y < 10; x++, y++)
44 views

### Running a complex notebook from a different master notebook?

I am trying to use the Dynamo notebook (https://www.ssc.wisc.edu/~whs/dynamo/dynamo_3S_v1.4.1.nb) in a loop over parameters. Basically, this software takes one matrix as input, solves ODEs and some ...
46 views

### The variable in the While loop does not change

I have a simple while loop. After running, the variable does not change: ...
52 views

### Return last value of While function

I want to make a function that performs a multiplication with Inner i number of times using a ...
63 views

### Variable nesting depth inside table

I hope my title makes sense. The idea is the make a function in which a set of variables, $l_1$, $l_2$, etc. are accessible inside the innermost body of a nested (/folded) function. Each of these ...
62 views

### How can I count the number of days (Monday, Tues, etc) in a year?

I am new to Mathematica and for fun am trying some of the challenges. The one I am working on now is: ...
137 views

...
197 views

### Parallelizing nested for loops

I'm currently computing nested for loops. I count up a few counting variables and compute a value for each set of counting variables, then that value is added to an array. It is a way of adding up ...
139 views

### Evaluating number of iteration with a certain map with While

Beeing used to programming in C-like languages I am struggling with iterations and loops with mathematica. I am trying not to use the For command, as already lots of people recommended. I am trying ...
125 views

### How do I create multiple plots from an Excel spreadsheet?

I have imported an Excel spreadsheet with dimensions {row, col}= {92, 28} into Mathematica, I want to plot 27 datasets from the spreadsheet: column 1 with column 2, column 1 with column 3, ..., column ...
166 views

### Mathematica crash every time when I run this loop [closed]

I have written a simulation for a percolation test. Then, I am using another notebook to control this simulation to generate 1000 results with a different random seed for each one of them. The ...
68 views

### Populating function inputs from lists [closed]

I have several lists containing variables, e.g. list1={x1,x2,x3}, list2={y1,y2,y3}, etc. I would like to define a function in those variables, i.e. ...
215 views

### Overloading a function to pass in an expression rather that the name of a function

This is an example of procedural programming borrowed from Paul Wellin's book. It's a simple implementation of the Newton-Rhapson method. I overloaded the findRoot ...
53 views

### Running a loop to check for multiple congruences

I have the code for a loop to run. Right now it can check if a number is a square and at the same time check if it is congruent 0 mod 47. My questions is, how can I alter the code to see if it is ...
48 views

### Loop with indexed function not defined for some index values [duplicate]

If anyone cares, this is supposed to be a very simple implementation of a Metropolis algorithm for a uniform distribution. I want to plot the variance of the sampled values as a function of an ...
81 views

### List defined in Do not remembered outside Do

Apologies if this is a trivial question. It comes from an overall problem I am having with Mathematica. Specifically, within a Do I generated the elements of a (...
124 views

### Using elements of list to solve a differential equation

I have created a list as shown in picture. the digits inside f are values of a and q respectively. I want to solve the Mathieu equation.....
153 views

### How do I repeat the number of times a nested for loop does an iteration?

I am trying to write a nested for loop that prints the pairs 00 through 55, with each digit running from 0 to 5. In other words, I want the output to appear as so: 00, 01, 02, 03, 04, 05, 10, 11, ......
59 views

### How to make a table for loops?

I have a code given by ...
179 views

### Why are there local variable conflicts in my recursive function definition?

Sorry to post a long piece of code. There are two places in here where I Print[] 'path2' when the count == 984, because for some reason, that list is getting ...
53 views

### Looping from a Set of Undetermined Size [closed]

For a problem I am working on, I need to create sets all the prime factors of a large set of integers (at least on the order of 1$-$1,000,000 but more on the order of all integers 1 to $10^{12}$). ...
62 views

### Nested Do loops with externally defined iterators [closed]

I want to be able to define a set of iterators for nested Do loops, such as ...
84 views

### What is wrong with my procedural function to find all prime $\leq x$? [closed]

I want to create a simple function that prints all prime numbers from 1 to x. I have the following code, which doesn't cause any errors from the kernel but it doesn't return anything: ...
271 views

### Is there any way that convert entire mathematica code to java or python?

I am novice to Mathematica. I want to convert Mathematica code from my textbook to Java or Python to trace coding.
38 views

### Problem faced using user-defined mod function in loop

I want to make a program which tell whether a number perfect or not.So i tried like that: ...
I am trying to create an $n \times n$ matrix, which has cosine terms. I would like to select the values of the arguments of cosine terms from a random set of values that I have generated. My code ...