# Questions tagged [procedural-programming]

159 questions
Filter by
Sorted by
Tagged with
99 views

### For loop from a continous position [closed]

I have a matrix A, which has its elements being function of m, say A[m_]={m, -m*m+2, 5x+m, 3*m+2, -m*m*m, -3+m, m, 5*m*m-4*m, 2*m*m*m} Now, there is a double ...
24 views

### How to enter solutions in LHS of an equation using loop to check RHS [duplicate]

Suppose I get 1 million values of a, b after solving the equation ax+by^2 =0. Then how to again put the values of a and b in the LHS of the given equation using a loop in order to check if the RHS of ...
50 views

### Loop plot using user defined data input

I am trying to run this code using a single loop. Values for variables $a$ and $b$ are user defined (not random data). Below is my code, ...
69 views

### Why doesn't my For-loop work? [closed]

I have the mathematica command ...
58 views

### How to write the values of a function after each iteration to a .dat file?

I have a differential equation which I solve numerically using NDSolve to obtain y[x]for different values of t. Example:t=0.00; ...
133 views

### Using a loop to build a list

I'm trying to take a list and then plot it with complex variables. However, when I'm making my list I keep getting Recursion depth of 1024 exceeded during evaluation of {test, nu} and my list is ...
67 views

### Can a For-loop be contained in a function?

What I want to do here is evaluate For[k = 1; t = Frr[1, 0, k], k < 1000, k++, If[k >= 3, Break[], t = Flatten[t]*Frr[1, 0, k + 1]]]; t in which ...
442 views

### Use of NDSolve in loops

Im new to mathematica and have some problems to use NDSolve in a loop (at least i suspect this is the reason for my problems). I hope anybody can help me! Thanks a lot in advance! I created the ...
117 views

### How to Map FindMinimum instead of using a For loop to return distance output?

I am looking for the distance between the spatial median of a subset of points to all original points in the set preferences to model group decision making. I can build a for loop to return the ...
319 views

### Fourier transform along only one dimension of 2D array

I'm a relative newbie to Mathematica Before you flag me as duplicate, note that I have read and studied "Fourier transform over a custom dimension" as best I can. I cannot understand the answer, it ...
68 views

### How to run this statement multiple times and put them in a matrix?

I have the following Mathematica Code. ...
2k views

### How to pass variables by reference and by value [duplicate]

I haven't seen this question specifically addressed before in this site, although some hints and traces have been given, for instance, here: Pass by reference for an option argument Does pass-by-...
268 views

### Writing my own code to find the power set of a set [closed]

(The Goal is to create a program that given an input set, yields an output showing the Power Set of the entered set without using the built-in mathematica function" "When I enter this code into ...
372 views

151 views

### Add two functions in a table with the same variables

How can I print the values of the function expere in the table of the function exper ... Note that I use this code ...
120 views

### How to label output in a Do[…] loop?

I have a huge list = {l1, l2, l3, ...}, which I want to output by labeled rows. My attempt was to ...
203 views

### Making a Double Loop with Specified Indices $(i,j)$

I want to make a double loop with Do. Let me first make a simple example. Consider the following simple double loop ...
5k views

### Creating a multiline function with localized variables

I would like to create a function with several expressions in the code body. For example, I would like to write something like this, but which will actually work. ...
100 views

### Repeating Calculations/Iterations without a specific function

I am trying to repeat an initial condition many times such that I get a desired final output. ONE final output depends on many subsequent calculations from ONE initial condition. But I want to get a ...
87 views

### Problem while adding elements to list in while function [duplicate]

I'm tring to write a little bit of code that adds a missing element to a list. In specific: given a numbered data set such as: ...
176 views

### Iteration problem using NestList or Do

I am trying to model a tank with discontinuous flow into the tank and discontinuous flow out of the tank. I do it numerically. You can imagine a tank to which I feed blue balls at timepoint t0, red ...
118 views

### Do loop with step size being being a doubling factor

Right now I'm doing loops like this: For[n=10, n<1000, n =2n, Do Stuff]. Is there a way to do this as a Do[] loop? I know ...
83 views

### Challenging antiderivative loop

I am attempting to create a loop (either Do, For or While) that will continue to take antiderivatives of f(x)= x until the area under it between 0 and 10 is greater than 1000. And whichever function ...
57 views

### How would you rewrite these procedurally coded internal routines in functional form?

I came across the following two internal functions SimplifyDumpAbsToSign and SimplifyDumpSignToAbs that have been written ...
238 views

### Out of memory in a Do loop

I have the following code: ...
664 views

### counting number of outputs in For loop

I am using For loop and If within it. For example: ...
381 views

### How do I achive the function of Continue using Catch and Throw?

Procedural programming is considered a bad practice in writing Mathematica code. But for education's sake, is there any way I can do Continue using Catch and Throw? According to WRI's documentation, ...
115 views

### Max iterations for NestWhileList [closed]

I'm writing Turing machines with a halting state. Many of these tms will never reach the halt state and I want a way to tweak NestWhileList so it runs a max of $n$ ...
63 views

### Not able to apply Scan in place of For loop [closed]

I have been advised to avoid procedural loops and use other functions like Scan,NestList, FoldList, NestWhileList, Inner and Outer. My worry is that if I have a need in which certain critical ...
239 views

### Table and IF statement

I want to make a table to get a nbyn matrix. However, the diagonal are divided by zero. For example: n = 5; Table[1/(Sin[i] - Sin[j]), {i, 1., n}, {j, 1, n}] I ...
762 views

### Do loop with If condition

I have the following formulas: 1- A cross section: sigma[beta_,alpha_,Y4_] := c^2/(256*Pi) * (1/2) ( Ytt[beta,alpha,Y4]/ m ) * Abs[A]^2 Where c is a strong ...
104 views

### Beginners problem, Do Loop, Eigenfunction iteration

I am trying to find the first Eigenfunction of the Laplacian (in 1D), i.e. a solution of $$u''(x)=k u(x)\\ u(0)=u(1)=0$$ with minimal $k>0$ (in this trivial example, I actually know the analytic ...
70 views

### Extract values from user-made procedures [closed]

I've been programming in Mathematica recently, and I'm stuck in the following problem: I define the following procedure ...
41 views

### How to Return[A++] then Re-initialize[A] ? For If[] = False [closed]

I'd like to make a program such as: A=1 B=-1 RandomInteger[{0,1},200]; If[#==0, A+=Abs[B];B, Return[A] then Re-initialize ?]& @/RandomInteger[{0,1},200] My ...
95 views

### Basic question about loops in mathematica

I am very new to Mathematica programming and am trying to find the optimum of a numerical integral for various values of a parameter. Here is the basic code for one parameter value that runs fine - I ...
435 views

### Trouble with Nested Do Loops [duplicate]

I have: myres = {}; Do[ Do[ Append[myres, {j, i}], {i, 1, 3} ], {j, 1, 5} ] However, when I run the code and then enter: ...
811 views

### For loop error: Tag Times is Protected [duplicate]

i want to use For loop into my analytical physics theory but my For loop is not working.? so please help me .here is my simple (for example code) ...
233 views

### Looping things in Mathematica

So let me start by stating I'm really new to Mathematica. Being a biologist.. I'm trying to make two different loops. And I've been googling around and looking at some youtube video. But, I'm getting ...
281 views

### For loop to perform a shooting search in NDSolve

First comes the disclosure: I am very new to Mathematica and not so much a numerical guy in general. I am having a hard time using the for loop routine in Mathematica the correct way as well as ...
51 views

### How to store values in when using Do? [closed]

I am trying to plot a DensityPlot of a following integral, but I don't know how to store values generated using Do in a usable format. Following is the code that I have. Please suggest me a solution. ...
423 views

### Iterating FindRoot to solve a differential equation

I am new to Mathematica style programming, better at traditional programming. I would like to know if I can create a table of results using FindRoot, where the ...
217 views

### How would one return from a place of a pure function's body using Return?

From previous answers, replies and discussions it is known, while not formally documented (even in the most recent Wolfram Language Documentation Center), that Return can be used in a two-argument ...
137 views

### Better to use loop or function when populated list?

In the past I have pretty much stuck to expression building when using Mathematica, but recently I have been writing a procedure to populate an array, which I guess are called "lists" in Mathematica. ...
192 views

### How do I make a definition/function/method as I would in Java/MATLAB/Python

I've been trying to figure this out for a few hours now and it's driving me nuts. I am trying to confirm that, after transforming a Schrodinger equation, that the new wavefunctions satisfy the new ...
572 views

### Mimic a procedural, recursive clustering algorithm for site percolation using functional programming

Sorry in advance for my logorrhea: I just want to make sure all of the information is here. Context and Question I am investigating site percolation on a square lattice. I have a working, depth-...