# Questions tagged [procedural-programming]

175 questions
Filter by
Sorted by
Tagged with
41 views

### For loop and predefined functions

I tried to write a function which is basically given by a for loop and some predefined functions. I checked already that all of the predefined functions are working, but somehow my for loop does not ...
44 views

### Table of tensor products [closed]

I wrote a function RUTable, which generates the tensor product of certain matrices. Now I want to write a function AvProb3, ...
39 views

### How to do loop with parameter steps [closed]

How to do loop with parameter steps For example I want print numbers : 1,2,4,8,16 but I don't know how to do loop code like this doesn't work Do[ Print[i] , {i, 1, 10, i}]
119 views

### Iterating with Do rather than NestList

This code below works fine for me. ...
52 views

### How can I multiply the elements of a list using loops?

{1,1,1,-2,1,2} How acn I multiply the elements in the list using loops?
44 views

### Creating indexed lists of solutions using Do Command

Why when I perform this code am I not producing lists called roots[j], each containing 3 elements which are the roots of the equation? When I type roots for example I get roots as answer ...
98 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 ...
42 views

### Replacing the input with output

I have the following code, ...
45 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 ...
40 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 ...
54 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 ...
68 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: ...
119 views

### Need help with ParametricNDSolveValue for ODE with two variables and Do-loop

I' m trying to solve a tricky 2-nd order ODE with ParametricNDSolveValue for boundary conditions (BCs) y = 0 at R and ...
58 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. ...
302 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 ...
68 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: ...
85 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) ...
74 views

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

Update A very crude attemp ...
95 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: ...
91 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 ...
81 views

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

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

### Changing iteration variable in Do loop

I want to generate random positive hermitian matrices, I start with such a code ...
32 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. ...
81 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 ...
75 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 ...
46 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 ...
51 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. ...
72 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++)
42 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 ...
49 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: ...
41 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 ...
57 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 ...
55 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: ...
113 views

...
93 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 ...
133 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 ...
115 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 ...
150 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 ...
66 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. ...
29 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 ...
127 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 ...
49 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 ...
41 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 (...