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 70

Questions about Mathematica's procedural programming paradigm.

2 votes
Accepted

What's wrong with While? Is it possible to use double While in a single code input?

I wanna get the second root that meet the criteria I set n^2 + n - 6 == 0 In this case you could do ClearAll[t, n]; n = -10; While[True, If[n^2 + n - 6 == 0, Break[]]; n++]; t = n + 1; While[Tru …
Nasser's user avatar
  • 150k
1 vote

How do I repeat the number of times a nested for loop does an iteration?

It is not a good idea to use For loops, if you must use explicit loops, you can use Do or Table Do[ Do[ myVar = ToString[i] <> ToString[j]; Print[myVar] , {j, 0, 5} ], {i, 0, 5} ]
Nasser's user avatar
  • 150k
2 votes

Question about for loop

As recommend in comments, better to use Table or Do. how I can get the value of S1 for each i value in the output. For For you can still use Sow and Reap as well result = First@Last@Reap@For[i …
Nasser's user avatar
  • 150k
1 vote

Save data from loop each determinate time

Do loop then I want to Save data from this loop each x number of iterations One way might be SetDirectory[NotebookDirectory[]]; fd = OpenWrite["foo.txt"]; xNumberOfIterations = 3; Do[ m = R …
Nasser's user avatar
  • 150k
4 votes

For Loop to Sum numbers in a list

List={3, -5, 2, -12, -4, -1, -8, 10} There are many ways to do this in Mathematica, without using For. One way could be to first filter out the positive numbers, then call Total list = {3, -5, …
Nasser's user avatar
  • 150k
5 votes

A loop in which three indices are changed

How could this piece of code be written in the Table, or as simple as possible? I would just replace the For by Do to keep things simpler and more clear ClearAll["Global`*"] LL = {1, 2, 3, 4, 5, 4}; …
Nasser's user avatar
  • 150k
0 votes

If statement inside a for loop to find a function?

Using the numbers you gave, it will take forever to finish. (it is also using For loop, which is slow). I fixed few things to make it run, and changed couple of numbers to make it finish quickly. It …
Nasser's user avatar
  • 150k
5 votes

Why won't my random walk work in a Mathematica Do loop?

Because the Do does not return value. i.e what is generated inside the Do does not show up on the screen. You either need an explicit Print from inside the Do to see the output, or use Sow/Reap to col …
Nasser's user avatar
  • 150k
3 votes

How can I make 10 variables from a for loop?

You could use ToExpression For[i = 0, i < 4, i++, ToExpression["b" <> ToString[i] <> "=" <> ToString[i]]] and now I am not sure why you want to do the above, there could be better ways to solve the …
Nasser's user avatar
  • 150k
1 vote
Accepted

Make a loop while graph is not empty

You can't assign value to input parameter in Mathematica as these are passed by Value. You were writing g = remmdv[g] but g is passed by value so raw object. Can't assign to or change raw objects. A …
Nasser's user avatar
  • 150k
2 votes
Accepted

Loop plot using user defined data input

One way might be to put your input in a matrix and then map over it ClearAll; f[a_,b_]:=a*x^2+b*x+12-a-b; input={{1,2},{2,2},{1,3},{1,4}}; plots={a=#[[1]];b=#[[2]];Plot[f[a,b],{x,0,10}, PlotLab …
Nasser's user avatar
  • 150k
6 votes

Calculating successive derivatives of a monomial list using a Do loop

Another possibility monlist = {c x^3, x^5, 4}; NestWhileList[D[#, x] &, monlist, Total[#] =!= 0 &] Edit And in the spirit of procedural like programming, here is my version monlist = {c x^3, x^5, …
Nasser's user avatar
  • 150k
1 vote
Accepted

How do I use Check with Table to skip results that contain error messages

Use === data = Table[If[Check[i^0, err] === err, Nothing, i], {i, {1, 0, 2, 0, 1}}] You should have used === in your Do loop also. But there because of Continue you did not notice as it was starting …
Nasser's user avatar
  • 150k
6 votes
Accepted

Save loop output in a data file

It is better to avoid For loops. And why not just use Export? And try to not use l for variable. Not a good choice as it looks like 1. SetDirectory[NotebookDirectory[]] ClearAll[x]; range = Range[1/10 …
Nasser's user avatar
  • 150k
2 votes

How to use module to assign functions to a set of imported text files?

Next, I would like to loop the whole process so that I don't have to copy and paste my code 8 times for each individual file. Since Import[..., "Data"] worked for you, why not use that? Someth …
Nasser's user avatar
  • 150k

15 30 50 per page