Questions tagged [procedural-programming]

Questions about Mathematica's procedural programming paradigm.

Filter by
Sorted by
Tagged with
0
votes
1answer
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 ...
0
votes
0answers
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, ...
0
votes
2answers
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}]
3
votes
2answers
119 views

Iterating with Do rather than NestList

This code below works fine for me. ...
1
vote
2answers
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?
1
vote
2answers
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[0] for example I get roots[0] as answer ...
2
votes
1answer
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 ...
1
vote
1answer
42 views

Replacing the input with output

I have the following code, ...
1
vote
1answer
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 ...
0
votes
0answers
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 ...
0
votes
1answer
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 ...
4
votes
1answer
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: ...
0
votes
0answers
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 ...
0
votes
1answer
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. ...
2
votes
2answers
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.
1
vote
1answer
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 ...
3
votes
1answer
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: ...
0
votes
1answer
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) ...
1
vote
2answers
74 views

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

Update A very crude attemp ...
3
votes
2answers
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: ...
1
vote
1answer
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 ...
1
vote
2answers
81 views

How can I plot these straight lines in a picture?

How can I plot these straight lines in a picture? ...
5
votes
7answers
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. ...
2
votes
3answers
87 views

Changing iteration variable in Do loop

I want to generate random positive hermitian matrices, I start with such a code ...
0
votes
0answers
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 ...
0
votes
1answer
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. ...
2
votes
1answer
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 ...
1
vote
0answers
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 ...
2
votes
1answer
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 ...
0
votes
0answers
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. ...
1
vote
1answer
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++)
0
votes
0answers
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 ...
0
votes
0answers
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: ...
0
votes
0answers
41 views

The variable in the While loop does not change

I have a simple while loop. After running, the variable does not change: ...
0
votes
1answer
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 ...
0
votes
1answer
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 ...
0
votes
0answers
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: ...
0
votes
2answers
113 views
0
votes
1answer
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 ...
2
votes
3answers
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 ...
1
vote
1answer
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 ...
0
votes
1answer
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 ...
2
votes
1answer
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. ...
0
votes
0answers
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 ...
3
votes
2answers
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 ...
0
votes
2answers
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 ...
2
votes
1answer
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 ...
0
votes
2answers
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 (...
0
votes
1answer
76 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.....
1
vote
3answers
87 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, ......