Questions tagged [procedural-programming]

Questions about Mathematica's procedural programming paradigm.

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

Assiging Plot Range to Variables Works For X but Not Theta

Observe the following Mathematica code: ...
0
votes
2answers
37 views

Create list of functions, domains, and iterate over (compare to Python code)

In Mathematica, I want to do a mass export of many different animated plots of specific functions with different domains. Because I don't necessarily want the plots to always have exactly the same ...
4
votes
1answer
217 views

how can i get the following figure using the for loop

how can i get the following figure using the for loop. n=5 For[i=1,i<5,i++,For[j=1,j<n,j++,A=(i+j)]] A//MatrixForm The code I found is above but not working....
2
votes
1answer
49 views

Build a list from events

Say I have a list of elements of type {name, direction, time} where direction can be in or <...
1
vote
1answer
23 views

Skip time taking loop values to take input next value after certain time

I am fitting using NonlinearModelFit, where I am trying to input guess values for parameters (g and xp1) from the for a loop. For a certain value of g or xp1, the loop takes infinitely long to compute ...
2
votes
1answer
88 views

Generating a lattice by $𝑁^{𝑡ℎ}$ iteration of unit cell

This question is in continuation of the my previous question that was not clearly presented by me at all. I have a unit cell, and I would like to generate a lattice but in iterative order. For ...
1
vote
0answers
44 views

Generate piecewise function using for loop

I want to specify a piecewise function by writing f[x_]:=Piecewise[piecewiseComponents], and use a loop to specify the components. I have tried ...
6
votes
1answer
48 views

Automatically set x=0, after each input/output ? ($AfterEachInputOutput)

Is it possible to do something that I want, after each input/output automatically and silently? I am looking for a feature like $AfterEachInputOutput in the following code : Example : to set variable ...
4
votes
2answers
134 views

Large matrix inversion

I'm still learning Mathematica, and I'm trying to write a program that needs to invert a large (nxn, n=160 or possibly larger than this) matrix with numerical entries, multiply with to another matrix, ...
0
votes
1answer
42 views

Draw specific polynomial with given roots by reading roots from txt file

i am new to mathimathica and i just can do basic things with it. i have a file.txt that contains roots of two polynomials $p(x),q(x)$. both polynomials have the same degre and first n numbers are ...
2
votes
0answers
61 views

Can I parallelize this function?

Can I and should I parallelize this function ? my aim is to have faster calculations below is a toy function in which I kept the structure of the real function I am using. It uses ...
1
vote
1answer
38 views

How to change numbers in variables defined with a loop?

I am trying to change the number which is part of the variable name with a loop. What I want to changue is the following: ...
1
vote
1answer
48 views
1
vote
2answers
108 views

Generating a $N^{th}$ iterative line graph from the adjacency matrix $M$. How to generate $M$?

I have a unit cell, and I would like to generate a lattice but in iterative order. For instance, consider the following example-- The unit cell is (zero iteration) This figure is generated by a ...
1
vote
2answers
102 views

Can one make `Do'-Loops of arbitrary depth?

In the documentation for the Do[...] function, a loop of nesting up to any number of layers is supported. But to apply their function, one needs to know ahead of time how many layers of loops they're ...
0
votes
3answers
80 views

Superimposed data on top of each other in a Do Loop

If I have 4 different types of data such (that I get from an Excel file) as: https://pastebin.com/j3Bgfxqm I am trying to implement a ...
0
votes
0answers
48 views

Slow evaluation of derivative of Solution of NDSolve

I need to perform a Fourier Transform on the results of a ParametricNDSolve function as well as on the derivative of one of the coefficients. Now I do this by ...
2
votes
2answers
137 views

Functional realisation of do-loop

I'm currently optimising my code and I'm using a lot of loops, so I was wondering if there is a smarter or faster way to do things like: ...
2
votes
1answer
121 views

Strange indexing behavior by Table

Maybe I do not understand how Table works, but I find this very confusing and it took me a long time to debug because this was part of a much more complicated routine. I am trying to build an array ...
1
vote
0answers
72 views

What is wrong with my code for implementing PSOR (Projected Successive Over Relaxation)? [closed]

I have written the numerical scheme of PSOR (Projected Successive Over Relaxation) method of a obstacle program in 1D, which is as follows: \begin{align*} &u_0=u_N=0\\ &u_i^{k+\frac{...
2
votes
1answer
46 views

Two different variables in a Do Loop

I am trying to use the code developed by @Alex Trounev here: Numerical solution of an iterative equation for different kind of q. I am not sure how to incorporate ...
6
votes
2answers
204 views

Check if rows and columns of matrices have more than one non-zero element?

I am given a list of square matrices (with non numeric entries but abstract symbols which are assumed to take real values) and I want to write a function that returns True if the following condition ...
0
votes
2answers
60 views

Using condition for each element of a matrix

I'm trying to write a code so that for each element of matrix C2 if the element i,j is equal to element j,i and it is equal to 1 then it adds one to a variable and if not it adds one to another ...
2
votes
5answers
399 views

Implementing Newton's Method?

For an assignment, I have to implement Newton's method using Module and a For loop. So far, I have ...
0
votes
2answers
117 views

How do I integrate a For loop to generate iterations of the Sierpinski's Triangle?

I'm sorry if this is a basic question—I don't know anything about programming. I know you can create a graphic of Sierpinski's Triangle with a single command, but I'd like to know how to create one ...
0
votes
1answer
74 views

Use of ParallelDo with an iterative or recursive calculation

Is it possible to use ParallelDo (or any similar parallelization method) to speed up the calculation of an iterative calculation, which takes a previous calculation ...
0
votes
0answers
57 views

Nested operations in Lists as a function of the times it is applied

I have a fixed list labels = Table[i,{i,k}] for some fixed $k$. There is a way of picking some sulists of this list with some property that I am interested in. I ...
0
votes
1answer
45 views
1
vote
1answer
100 views

How can I find different areas of triangles from a list of points?

If I have a list of points such as {{1, 1}, {4, 7}, {24, 67}, ..., {17, 83}}, how can I find the area of triangles formed by different combinations of these points? ...
0
votes
2answers
41 views

Find the roots of a list of derivatives

I want to be able to take a polynomial and take the 1st 5 derivatives, then add at least one root of each derivative to a list using a loop. However, each attempt I try only ends up outputting the ...
0
votes
1answer
47 views

Getting error messages form Set while trying to implement the bisection method with a For-loop [duplicate]

My objective is to build a function using modules that runs the bisection method. I have a working bisection method but when I try to implement it as a module I keep getting this error and I can't ...
0
votes
0answers
60 views

Code breaks as soon as I try to print a variable

Edit I think I figured out what was wrong. Since I was adding in Print[m] after I ran the loop, I had to clear my variables if I wanted to run the loop again. I ...
1
vote
1answer
48 views

Use of a For/While loop inside another For/While loop for dual integration [closed]

Can anyone please give suggestion for using For/While loop inside For/While loop for integrating a function with respect to two variables say for- $\qquad r = (x^2 + (a/y^2))^(-1/2)$ Integration is ...
2
votes
1answer
80 views

How to write this simple task of unimodular prime search in mathematica?

For testing a particular algorithm I found mathematica is the best way as it has all the tools I need. I am stuck in a number theory part and since I am not an expert in mathematica I do not know how ...
1
vote
1answer
94 views

How to build a tri-diagonal matrix [closed]

I have an algorithm that works for a Tri-Diagonal matrix in Mathematica, but I need a good way to build my starter matrix A. It's a 20 variable system (and will be a 200 variable system once I get it)...
0
votes
0answers
52 views

Giving variable inside WhenEvent a value

I am defining ParametricNDSolveValue in one cell and then using this in another one to find the parameter value using bisection. For clarity, I have simplified my differential equation. In order to ...
0
votes
0answers
41 views

Problem with batch processing of images

I am having some problems with a palette I have designed to apply identical image processing to microscopy images. I would like to apply identical processing across a folder of images (representing ...
1
vote
1answer
42 views

How can I apply code that calculates one element of a list to the whole list?

I have a problem with a while loop in Mathematica. I want to run the whole list "mFromAlice" in the while loop but I dont know how to do that. It works with the first row, which is named x ...
1
vote
0answers
28 views
0
votes
0answers
53 views

Loop function for a list of codes

I have a list of codes that start with importing column D of an excel sheet which has a hyperlink. Then, the code moves onto importing the text version of the hyperlink and further proceeds with ...
0
votes
0answers
48 views

Avoiding Tables, Do and other loop construction

In my work I have a lot of cases, where I should calculate non-listable functions for a quite large number of points. To be more concrete, consider first listable function ...
3
votes
3answers
166 views

How can I get the While function to evaluate two conditions simultaneously?

This is probably a basic question but I'm having trouble in writing a While conditional that evaluate two conditions at the same time. I have the following code. The idea is to generate two random ...
1
vote
2answers
83 views

For loop, use past iteration

So I'm trying to use Newton's method to find the root of a function. The code works, what isn't working is my absolute error calculation. What I need is to subtract my past iteration from the current ...
0
votes
0answers
52 views

Alternative to procedural loop with evaluation of notebooks

very new Mathematica user here. I am struggeling with programming Mathematical-like and would appreciate some guidance. I set up a main notebook which calls various sub-notebooks: ...
6
votes
3answers
422 views

Create variables in a for loop

I am very new to mathematica, but it would be much easier for me to use For loops in order to create variables. My train of thought was simple, but apparantly does not work. Let's say I defined these ...
1
vote
1answer
67 views

Code to generate many Do-loops, where the $i$-th loop has upper bound given by $f(i$)

How do I get Mathematica to run an arbitrary number of Do-loops, where the i-th loop it upper bound given by some function $f(i)$? I badly need help with this. Let's denote the desired code by ...
0
votes
1answer
53 views

RandomReal inside a loop

I want to perform the following series summation: $$\sum_{j=1}^5 \exp\left[{-\beta \, \left(\text{En} + \frac{\Delta \, X}{Num} \right)}\right] \cos{\left(\text{En} + \frac{\Delta \, X \, T}{Num} \...
6
votes
5answers
353 views

Replace elements of a list based on a function

I have a function of k (written in the form of a table/list to get values) for 16 integer values from 1 to 16: f = Table[3*k*k, {k, 1, 256}] I want to replace ...
1
vote
0answers
42 views

How do you stop a For loop from progressing until a condition has been met?

I have a matrix and the generation of a number between 0 and 1 (this number will act as a probability): ...
1
vote
1answer
115 views

Translating pseudocode for the Jacobi algorithm into Mathematica

Here is an image for the Jacobi algorithm. I have almost no knowledge of Mathematica, the textbook does not help. Does not provide examples. The class average is 64%. I just want to be able to ...

1
2 3 4 5 6