# Questions tagged [procedural-programming]

160 questions
Filter by
Sorted by
Tagged with
64 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: ...
65 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) ...
72 views

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

Update A very crude attemp ...
82 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: ...
79 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 ...
80 views

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

How can I plot these straight lines in a picture? ...
277 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. ...
71 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 ...
70 views

### Changing iteration variable in Do loop

I want to generate random positive hermitian matrices, I start with such a code ...
30 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. ...
72 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 ...
34 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 ...
66 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++)
50 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. ...
41 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 ...
48 views

### Iterative loop with many steps

I want to automate the following code, let me begin by explaining the code first. This code, for representation, is divided into 3 parts. The first is: ...
38 views

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

I have a simple while loop. After running, the variable does not change: ...
51 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 ...
44 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 ...
131 views

### Why can't I iterate?

I encounter a problem when computing the following equations: ...
55 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 ...
310 views

### Solving Bethe ansatz equations

I'm very new to Mathematica. I want to solve the Bethe ansatz equations for the so-called "Hofstadter-problem". These equations take the form: z^2_{l}=q^{Q} \prod^{Q-1}_{\substack{m=1\\m \neq l}}\...
45 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: ...
99 views

...
57 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 ...
129 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 ...
100 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 ...
139 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 ...
63 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. ...
27 views

### Running a test over a list to alter list

I'm quite new to this. I have a nested list that represent solutions to an equation. I would like to create a new list that only contains one 'representative' of each element. As an example, imagine I ...
105 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 ...
34 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 ...
80 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 (...
52 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.....
66 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, ......
56 views

### How to make a table for loops?

I have a code given by ...
97 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 ...
48 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}$). ...
61 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 ...
75 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: ...
96 views

### My code for iterating GPS receiver location doesn't work [closed]

This is a line of code i've utilised in order to iterate for GPS location i've tried to base it off this guys code, https://math.stackexchange.com/questions/1445808/newton-raphson-method-in-gps?...
146 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.
29 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: ...
25 views

### Looping Constructs to create a set of varibale matrices

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 ...
252 views

### Solve a system by Cramer's rule using loop

Consider the linear system AX=B,where A={{3, 0, 2}, {-3, 2, 2}, {2, -3, 3}},B={{3}, {-1}, {4}} and x=...
103 views

### How to use a test function correctly to terminate a While loop?

I define a test function in order to stop my While loop: ...
163 views

### How to generate repetitive graphs?

I need to create several graph for different values of a parameter $h$. The code is the following ...
250 views

### Populating an array in do loop, allocating memory or not

I am doing a calculation where I have a do loop can be as long as 1 million. In each loop, I want to store a value into an array to plot afterward. In MATLAB normally I was preallocating the memory ...
60 views

### Iterative loop for a given list

Suppose I have the following list: ...