Stack Exchange Network

Stack Exchange network consists of 174 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.

3
votes
1answer
99 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
50 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
85 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
146 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
174 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
142 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
40 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 ((...
8
votes
2answers
141 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
427 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
42 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
96 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
60 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
68 views

Using While properly

I am trying to make While[] work with function results and evaluate them at the same time. ...
0
votes
1answer
76 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
88 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
54 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
53 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
119 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
44 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
49 views
0
votes
4answers
117 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
238 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
60 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
51 views

Iterative loop for a given list

Suppose I have the following list: ...
0
votes
1answer
41 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
284 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
65 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
56 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
119 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
53 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
65 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
52 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
86 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
92 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
74 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
58 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
354 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
513 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
135 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
95 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
179 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
50 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
59 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
42 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 ...