MicroClue
MicroClue

Reputation: 33

Mathematica Do/For loop with "Delete" or "Drop" does not work

initlNum453 = List[];
num1 = 2;
(*Pt1, initial work to make initlNum full of good variables*)
algorithmicNum = 1;
For[i7 = 1, i7 <= (num1 + 1)^2, i7++,
AppendTo[initlNum453, algorithmicNum];
If[((algorithmicNum) == (num1 + 1)), algorithmicNum = 1, 
 algorithmicNum++];
];

(*Pt2, delete unneeded variables*)
deleteValue = 1;
Do[
Delete[initlNum453, deleteValue];
 deleteValue = (deleteValue + num1 + 2);
 , {num1 + 1}
]

Here's a snippet of the code I'm trying to make (it involves pseudo-automating Lagrange polynomials). It should be simple; the first part creates a series of numbers in a list, and then the second should be delete a particular section (e.g., the 1,4,7 if n=2).

For some reason, one of the following occurs:

  1. No Error, but the elements in the list remains the same/no elements get deleted
  2. Taking out the semicolon says that the "Tag Times in ___ is Protected"-- can someone explain what exactly this means?
  3. When putting this into a Module, the error states that the expression .' cannot be used as a part specification. Use Key[.`] instead.

In any case, I don't understand why something as simple as this is just doesn't work on Mathematica. The "Delete" function works outside of a for/do loop, but doesn't inside-- can someone explain why or tell me what I did wrong?

Thanks for your help! I appreciate it!

Upvotes: 1

Views: 737

Answers (1)

Chris Degnen
Chris Degnen

Reputation: 8655

You need to write something like

initlNum453 = Delete[initlNum453, deleteValue]

Upvotes: 2

Related Questions