Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 46318

Questions about Mathematica's procedural programming paradigm.

4 votes
Accepted

Query in For loop

there are several things wrong: The "Continue[]" is not needed You need 2 closing brackets at the end. y1 should be a vector with values. y[[1]],y[[2]], y[[3] are not specified I added two print s …
Daniel Huber's user avatar
  • 56.4k
3 votes
Accepted

While loop not working problem

Commands in MMA are capitalized. You need "While" and "If". Then s and sum are 2 different variables. Here is your corrected code: sum = 0; i = 0; While[Fibonacci[i] <= 2000000, If[OddQ[Fibonacci[i …
Daniel Huber's user avatar
  • 56.4k
2 votes

How to change numbers in variables defined with a loop?

If you want the side effects of the list, not the list itself: Clear["Globals`*"] fun[n_] := ToExpression[ ToString[ StringForm[ "r`1`i=fuv`1`[w`1`]+fuv`1`'[w`1`] \ (c-w`1`);r`1`f=fuv`1` …
Daniel Huber's user avatar
  • 56.4k
1 vote

Do loop so that I do not get double terms?

Often a problem is easier, seen from another perspective. You have different quantum states, specified by 3 integers. We may e.g. represent these as lists: states=Flatten[Array[{#1, #2, #3} &, {3, 3, …
Daniel Huber's user avatar
  • 56.4k
3 votes
Accepted

An example code for doing a loop

First we define the conditions: Clear["Global`*"]; list = {a, b, c, d}; f1[a] = 0; f1[b] = 0; f1[f2[c]] = 0; f1[f2[f2[d]]] = 0; Then we apply the 3 steps. The result is accumulated by Sow/Reap in the …
Daniel Huber's user avatar
  • 56.4k
3 votes

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

Consider the cells as a grid. Then the 0 generations has the coordinates: {0,0}. The first generation has coordinates: {-1,0},{1,0},{0,-1},{0,1}. The second generation: {-2,0},{-1,1},.. Note that the …
Daniel Huber's user avatar
  • 56.4k
2 votes

Optimizing operations between vectors

Instead of creating a space grid, we simply imply integer coordinates from 0 to n. E.g. {0,0,0} indicates the cell at the origin. {1,0,0} the next cell along the x axis etc. Then we can get the cell n …
Daniel Huber's user avatar
  • 56.4k
3 votes

Quit the loop if encounter error message

Loops are seldom used in MMA. Most of the time loops ca be avoided and replaced by more efficient constructs. However, if you insist on using loops: At the start of the loop you already know the lengt …
Daniel Huber's user avatar
  • 56.4k
1 vote

Superimposed data on top of each other in a Do Loop

After importing your data, I needed some fixes to convert it to numerical data: dat = Import["https://pastebin.com/j3Bgfxqm", "Data"][[1]]; dat = ToExpression[ StringCases[#, "{" ~~ NumberStrin …
Daniel Huber's user avatar
  • 56.4k
2 votes

Superimposed data on top of each other in a Do Loop

In MMA using Loops is not advised. Instead, use Map and a function. Here is the procedure. Assume that we want to overlay dataset2, dataset3,.. onto dataset1 We again need data: dat = Import["https:// …
Daniel Huber's user avatar
  • 56.4k
1 vote

Sorting a list by increasing order algorythm

First, loops are seldom needed in MMA, there are more efficient operators for this, e.g. "Map". Second, your algorithm does not order the list. After the first round, the smallest element is at the be …
Daniel Huber's user avatar
  • 56.4k
2 votes

Trying to apply numerical method with Do

Your algorithm has a bug. Look at your function Fa1n and consider: ClearFa1n]; Fa1n[0,0]:: First, it sets Fa1n[0,0]=0, Fa1n[0,-1]=0 and then Fa1n[0,1]= Fa1n[0,0]+Fa1n[1,0]. However Fa1n[1,0] is not ye …
Daniel Huber's user avatar
  • 56.4k