Questions tagged [procedural-programming]

Questions about Mathematica's procedural programming paradigm.

Filter by
Sorted by
Tagged with
2
votes
2answers
58 views

How can I store vectors in a matrix

I am triying to generate realizations of a Gaussian random process using the KL expansion. For that, I need to multiply an eigenvector for an eigenvalue and a random variable. I have tried ...
1
vote
1answer
100 views

Repeating and Sequencing Procedures with two Do-loops

I have a Do loop where I'm looking for the value of certain parameters that respect the conditions inside an If, and with those values, a run another Do to make another calculation of an expression ...
1
vote
1answer
43 views

How to get a loop for a differential equation system?

I would like to know how can I obtained a loop of this system ...
0
votes
0answers
43 views

Replacing the print display in a for loop

I am running a For loop as follows: table = {}; For[n = 0, n < 10, n++, {table = Append[table, n], Print[table]}] I was wondering if there was a convenient way ...
2
votes
1answer
60 views

Matrix or loops or any ideas for help me

I have input data as below: ...
-3
votes
2answers
82 views

How to change a Do loop to a For loop? [closed]

I'm a rookie in the loops. I would like to use a For loop to get a solution like using a Do loop. ...
1
vote
1answer
66 views

How to change a Do loop to a while loop?

I'm a rookie in the loops. I would like to use a While loop to get a solution like using a Do loop. ...
1
vote
1answer
55 views

Assiging Plot Range to Variables Works For X but Not Theta

Observe the following Mathematica code: ...
0
votes
2answers
41 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
219 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
29 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
106 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
52 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
49 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
149 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
48 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
39 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
115 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 ...
2
votes
2answers
107 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
88 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
50 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: ...
3
votes
1answer
127 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
49 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
258 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
71 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
408 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
118 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
81 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
58 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
102 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
43 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
48 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
61 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
53 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
82 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
108 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
53 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
45 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
29 views
0
votes
0answers
54 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
51 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
198 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
112 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 ...

1
2 3 4 5 6