Questions tagged [procedural-programming]

Questions about Mathematica's procedural programming paradigm.

Filter by
Sorted by
Tagged with
0
votes
2answers
71 views

A list of operators in the For cycle

I'm pretty sure that analogous questions have been asked here a zillion of times, but... I think it is pretty straightforward from the code what I expect it to give: ...
1
vote
0answers
73 views

Using While properly

I am trying to make While[] work with function results and evaluate them at the same time. ...
0
votes
1answer
106 views

Randomizing Initial Conditions of NDSolve Differential Equation Phase Space Plots with Looping Structures

I am looking for a way to randomize the initial conditions on the numerical approximation for the angular displacement of a plane pendulum. I have been trying for hours, and believe a For loop is ...
1
vote
1answer
146 views

Golden section search method that terminate after $n$ iterations

I am attempting to code a program that executes the golden section search method and I would like to terminate the computations after $n$ iterations, where the user decides what $n$ is. My code works ...
0
votes
2answers
55 views

Loop doesn't hold the value

My program doesn't hold the value in a variable as I want it. I want to attach the calculated value as a list in a variable. What is wrong here? ...
0
votes
1answer
59 views

Do-loop with ParametricNDSolveValue not giving expected results

I have written code that using a Do-loop. In the loop I am changing the value of x, v, l and R, and looking at the computed ...
3
votes
1answer
337 views

Encountering 'Error: Set::setraw: Cannot assign to raw object' during procedural function definition

Sorry for the rather vague title, but I don't know what is wrong with my code. Here is a Ruby version of what I'm trying to do: ...
0
votes
0answers
51 views

Using Map function with NDSolve

I would like to solve a set of differential equations but vary one parameter, KieP, between 900 and 1100. The solution for a given parameter has many peaks. I would then like to interpolate between ...
1
vote
2answers
87 views
1
vote
0answers
65 views

While loop with changing variable , NDSolve and an Integral

Complete Edit: The Following code is new ...
0
votes
4answers
133 views

How to use If and Goto in Table loop? [closed]

I have the following code, j=0; Table[{Label[1], j = j + 1, i, If[j == 2, Goto[1], Continue]}, {i, 1,10}] which does not work; I get ...
4
votes
2answers
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 ...
0
votes
2answers
99 views

Nested For loops simplified

In order to avoid a deep set of nested For loops, I came up with this method to do it with one For loop. The range of each level's For loop counting variable k1, k2, k3,... is 0 to b, and n is the ...
1
vote
1answer
59 views

Iterative loop for a given list

Suppose I have the following list: ...
0
votes
1answer
43 views

Function of a function using SphericalPlot3D

If anyone has any idea how to turn all of that plotting stuff (hcpii4plot) into a function which takes hcpii4angfunc[θ, ϕ] as an ...
2
votes
1answer
88 views

Run a do loop from a high iterator value to lower [closed]

I wanna have a do loop that runs from the a high number to a smaller one. That is, if we have Do[Print[n],{n,1,4}] I would get 1,2,3,4 in the output. I rather ...
4
votes
5answers
295 views

How to build these functions without nested For loops?

I am trying to solve the 8-puzzle using two heuristics, which are: Pieces out of place and Distance Manhattan. After consulting several websites for example see and some books, I'm with some doubts, ...
0
votes
1answer
74 views

Want help with debugging a For-loop

I'm trying to run a simulation, which at the end gives a value 'qber'. Now I want to run this simulation multiple times with different values of 'p' each time. And these value of 'p' are actually the ...
2
votes
1answer
67 views

Code for finding multiple roots only finding two

I've an issue with my code. I am basically trying to get the n-th root of a function. My code finds two roots correctly, but for others, which I think should be distinct, I get the two roots repeated ...
2
votes
4answers
134 views

How do I use the values generated in a for-loop in my first iteration to my next iteration?

This one is somewhat hard to explain, but I'll try my best to. I'm trying to generate a list of numbers (containing only pi/10, 0, -pi/10). Numbers are randomly selected from these 3, where the ...
1
vote
1answer
60 views

Combined Plot of a loop

I want this program to plot to be combined into one plot - just can't seem to make it appear in one plot. Any suggestions? ...
0
votes
2answers
69 views

Save data from loop each determinate time

I have a Do loop then I want to Save data from this loop each x number of iterations. My Do ...
0
votes
0answers
65 views

Iterating a Module

I have a Module that can act on other Modules, which is given as Kk[EE,p,z1,z2,z3,K_func] and I am trying to iterate it, such that ...
2
votes
2answers
146 views

Looping over two variables [closed]

Suppose I have $t=4, 2, 5$ and $v=5, 7, 4, 8, 0, 5$ and $equ=A v/t$. I would like to calculate $equ$ at a single value of $t$ by using all $v$ values and then move to next value of $t$. How can I ...
0
votes
2answers
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?...
2
votes
1answer
77 views

Confused why my program won't define this

I legitimately think the problem is that pwgenerator isn't getting defined, but im' not sure why. Any ideas? On mine, when i run this to define it, pwgenerator stays blue for some reason, and it didn'...
0
votes
1answer
68 views

Loop command in Interpolation

I have a following interpolation function A[x,y] defined below. The variable y has some fixed range which is different for each <...
2
votes
2answers
419 views

For/ Do loop on a lists of two variables

I am trying to get an output of the following kind Out = Do[Evaluate[f[x,y]],{x,table1},{y,table2}] Here Out is a N-times-1 dimensional array/list and N is the ...
2
votes
3answers
578 views

Is for loop suitable for functions?

I have a question about for loop. In this example i made For loop without function, like this ...
0
votes
1answer
41 views

Looping on ranges (Modular iterations)

Is it possible to make the following code modular, so that it works up till depth n, and returns an array of all possible combinations for used{}? ...
0
votes
1answer
205 views

Collatz Conjecture [duplicate]

By definition of Collatz Conjecture or $3n+1$, regardless of the sequence (ie.$ m1,m2,m3....mn$), at the end, it eventually produces 1 at the end. For example, if ...
0
votes
1answer
102 views

successive iteration

I hope you can help with a problem I am having. I want to solve this equation $$\left( n^2 \Theta^2 + 2\alpha n\Theta -1\right)R_n = \frac{1}{R_0^2}\left( 2 \sum_{m=1}^\infty R_{n+m}R_m + \sum_{m=1}^...
0
votes
1answer
243 views

Using Random walk on a region [duplicate]

I want to simulate a random walk on two dimension equation using module. Checked the input so the path works ...
1
vote
1answer
53 views

Do Loop For Sets of Variables

Can I create a Do loop where instead of varying only 1 variable, I vary multiple sets of variable ? For example (the syntax is invented and only serves as a ...
0
votes
1answer
83 views

numeric parametric sweep for specific parameter

Let's say I have the following set of parameters: param= {a->1,b->2,c->3} and the following function that uses the parameters: ...
1
vote
1answer
44 views

Series of List manipulation Question

Given a list {{{a1},{a2},{a3},{a}}, {{a4},{a2},{a6},{a}}, {{a7},{a8},{a9},{a}}, {{b1},{b2},{b3},{b}}, {{b4},{b2},{b6},{b}}} I want to change this to ...
1
vote
0answers
78 views

How can i set up an If or Do loop to follow this calculation procedure?

The following picture depicts the calculation procedure I wish to set up. The inputs are $T_r$, the chemical composition of the feedstock and constraints defined by the equivalence ratio. This ...
0
votes
1answer
333 views

Creating an array with “For” loop

I need to perform a number of operations within a For loop and store the results in an indexed array (without using the Append function) For examole (to make it ...
0
votes
1answer
123 views

Want advice on writing better code to do matrix calculation [closed]

I want to perform the computation shown in the code given below in a much faster way. I have three loops for e, i and ...
0
votes
1answer
167 views

Recursion limit reached in a list of recursive functions

Here is a fragment of the code I was working on the other day, that is constructed from a recursive function with Memorization, whose input is prepared in a For loop and then modified as a boundary ...
2
votes
2answers
81 views

Organization of repetitive code

I have a lot of data organized in Datasets. In the end I'm using ErrorListPlots to show different variables. Therefore I have to ...
0
votes
1answer
50 views

Error when calculating more than 1 input

I'm trying to solve a problem where I can't do more than 1 calculation inside a Module here. I have a list of numbers where ...
2
votes
2answers
309 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}}\...
1
vote
1answer
57 views

How to implement recurrence operations efficiently?

This question is related to this one. I basically want to partition a volume recursively. Consider a volume as vol = ExampleData[{"TestImage3D", "MRbrain"}]; ...
1
vote
0answers
55 views

Execute a notebook with a changing variable

I have created a notebook with one fix variable that I want to run from 1 to 100. Every time the whole notebook (all cells) shall be executed for the given number. At the end of the notebook, it shall ...
1
vote
0answers
50 views

Using Iterators within the WebSearch Command

I am currently trying to use the WebSearch command within Mathematica to search names from a Dataset that I have already imported. The names that I am trying to search are located in the 4th column of ...
0
votes
0answers
24 views

Finding trivial solutions, of the type 0 = 0, of an equation involving su(N) structure constants

so I have a bunch of equations $f_{abc} = f_{egd}m_{ae}m_{bg}m_{cd}$ (sum over repeated indices), where $f_{abc}$ are the structure constants of $su(N)$, for some $N$, and $m_{ab}$ are elements of ...
5
votes
1answer
221 views

Newton's Method for Robotic Arm with Constrained Motion

My question is related to the system in Using a Grobner basis to calculate common roots of a system of polynomial equations, but I am trying to solve with Newton root-finding methods the inverse ...
0
votes
1answer
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 ...
1
vote
0answers
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 ...