Questions tagged [procedural-programming]

Questions about Mathematica's procedural programming paradigm.

Filter by
Sorted by
Tagged with
0
votes
1answer
51 views

Why do I not see any results from my For-loop?

I am sure I am missing something trivial :-( Still any help is welcome. ...
2
votes
1answer
56 views

Breaking the outer Do loop by a condition in inner 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
68 views

For- loop which can reuse updated values [on hold]

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
30 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
49 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
59 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
28 views

Is it possible to create procedural lossless data compression? [closed]

Is it mathematically feasible to work on a recursive algorithm that, given a formulae, entry values, and number of rounds, could generate the very binary representation of a given file? So instead of ...
0
votes
0answers
37 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
46 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
36 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
50 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
54 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
42 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
98 views
0
votes
1answer
51 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
125 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
96 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
135 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
63 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
27 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
91 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
44 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
33 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
48 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
63 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
55 views

How to make a table for loops?

I have a code given by ...
1
vote
1answer
93 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
47 views

Looping from a Set of Undetermined Size [closed]

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
60 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
74 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
130 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
29 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
25 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
225 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
100 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
131 views

Why can't I iterate?

I encounter a problem when computing the following equations: ...
2
votes
4answers
161 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
186 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
157 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
156 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
456 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
44 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
107 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
70 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
138 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? ...