Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [procedural-programming]

Questions about Mathematica's procedural programming paradigm.

2
votes
1answer
27 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
75 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
47 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
55 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, ......
0
votes
1answer
49 views

How to make a table for loops?

I have a code given by ...
1
vote
1answer
75 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 ...
2
votes
1answer
45 views

Looping from a Set of Undetermined Size

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}$). ...
1
vote
1answer
57 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 ...
2
votes
2answers
70 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: ...
3
votes
1answer
105 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.
0
votes
1answer
25 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: ...
0
votes
1answer
24 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 ...
0
votes
1answer
83 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=...
0
votes
1answer
93 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: ...
0
votes
1answer
94 views

Why can't I iterate?

I encounter a problem when computing the following equations: ...
2
votes
4answers
154 views

How to generate repetitive graphs?

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

Improving performance of algorithm to compute Code puzzles

I hope to explore Mathematica by using it for Advent of Code puzzles this year, so spoiler alert for anyone interested in solving https://adventofcode.com/2018/day/1 for themselves. Part 2 of ...
1
vote
1answer
153 views

While loop (or alternative) to generate list of random submatrices satisfying condition

I'm trying to generate a list of random submatrices with matrix norm 0.1, however I'm getting stuck; currently my code looks like this, where I run over a while loop. ...
0
votes
1answer
42 views

How could I iterate the following equations?

It's my first time to use mathematica, and I hope to iterate the following equations. Ci0=-Ci-1,0 ((i-1+q)p a-p q c)/((i+q) p-p q) C0j=-C0,j-1 ((q p b-(j-1+p) q d)/((q p-(j+p) q) Cij=-(Ci-1,j ((...
9
votes
2answers
149 views

Problem with Excel operation in NETLink way

I'm using the NETLink package to build a Excel file and trying to fill it with some data as this: ...
5
votes
1answer
446 views

An efficient way to translate a triple for-loop from Matlab to Mathematica

This is my first post on StackExchange, so if I violate any etiquettes, I apologize in advance. I am a senior engineering student who has been using Mathematica for a year now. For one of my classes, ...
0
votes
2answers
43 views

Expressing values from an evaluated If function as a list

For[i = 0, i < 4, i++, Print[i]] gives the result: 0 1 2 3 by the definition of the If[] function. Given a much longer ...
3
votes
2answers
102 views

Programming with Mathematica Syntax - Dunford decomposition

I am always amazed while I am reading some solutions of problems in mathematical problems of this site with Mathematica. For instance, look at the problem 48. Whereas I am writing 100 lines of code ...
0
votes
2answers
64 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
71 views

Using While properly

I am trying to make While[] work with function results and evaluate them at the same time. ...
0
votes
1answer
81 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
101 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
54 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
179 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
47 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
0answers
53 views
0
votes
4answers
126 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
241 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
65 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
53 views

Iterative loop for a given list

Suppose I have the following list: ...
0
votes
1answer
42 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
87 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
288 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
67 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
59 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
125 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
55 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
67 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
54 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
95 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
94 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
75 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
62 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 <...