Updating a Vector in a For Loop: Troubleshooting Tips

  • Context: Mathematica 
  • Thread starter Thread starter member 428835
  • Start date Start date
  • Tags Tags
    Loop Vector
Click For Summary

Discussion Overview

The discussion revolves around troubleshooting issues related to updating a vector within a For loop in Mathematica. Participants explore the syntax and functionality of the code provided, seeking to understand the expected output and diagnose potential problems.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • One participant expresses difficulty in updating a vector and seeks assistance with their Mathematica code.
  • Another participant questions the syntax used, initially unsure of the programming language, later identifying it as Mathematica.
  • A participant asks for clarification on what “it’s not working” means, indicating a need for more specific information about the issue encountered.
  • Suggestions are made to simplify the code to verify the loop's functionality and to check for a stepping debugger in Mathematica for diagnosis.
  • One participant explains that the use of // modifies the output, leading to a return value of Null instead of the expected vector update, and suggests a correction to the code structure.
  • A later reply indicates that the original poster has resolved their issue, but does not specify how.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the initial problem, as the original poster's issue remains somewhat vague. Multiple perspectives on the code's functionality and potential corrections are presented without resolution.

Contextual Notes

There are limitations in the clarity of the original problem statement, as well as potential misunderstandings regarding the behavior of the code in Mathematica. The discussion does not resolve the specifics of the output expected versus what was received.

member 428835
I am trying to update a vector. I have tried this but it's not working. Any ideas?

\[Lambda] = {1, 2}
For[\[CapitalLambda] = 0.1, \[CapitalLambda] <=
0.2, \[CapitalLambda] += 0.1, \[Lambda] =
Catenate[{\[Lambda], {\[CapitalLambda]}}] // Print]
 
Physics news on Phys.org
Dumb question, but what language is this? I don't recognize the syntax.

Edit: Ah, just noticed the Mathematica tag. Sorry. Maybe someone more knowledgeable with Mathematica can figure it out.

What are you expecting to be the output? It looks like you intended Lambda to be concatenated with the values taken by CapitalLambda, so at the end it should look like {1, 2, 0.1, 0.2}?
 
joshmccraney said:
I have tried this but it's not working.
What do you mean by “it’s not working”? What happens?
 
Have you tried to simplify it to verify the loop itself works?

Is there a stepping debugger in mathematica that you can use to diagnose the issue?
 
joshmccraney said:
\[Lambda] = {1, 2}
For[\[CapitalLambda] = 0.1, \[CapitalLambda] <=
0.2, \[CapitalLambda] += 0.1, \[Lambda] =
Catenate[{\[Lambda], {\[CapitalLambda]}}] // Print]
The // modifies what it operates on. What you get back from
Code:
\[Lambda] = Catenate[{\[Lambda], {\[CapitalLambda]}}] // Print
is not λ but a Null,

Edit: the above is not well formulated. What I mean is that what is on the right-hand-side returns Null, so it is equivalent to λ = NullIn[16]:= FullForm[Sqrt[2]]
Out[16]//FullForm=
Power[2, Rational[1, 2]]

In[17]:= FullForm[Sqrt[2] // Print]
##\sqrt{2}##

Out[17]//FullForm=
NullYou have to instead use in the For loop
Code:
\[Lambda] = Catenate[{\[Lambda], {\[CapitalLambda]}}]; Print[\[Lambda]]
 
Last edited:
  • Like
Likes   Reactions: mfb and Dale
Thanks all! I would have replied a while ago but for some reason I did not receive email notifications. I have it working!
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 29 ·
Replies
29
Views
5K
  • · Replies 12 ·
Replies
12
Views
5K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 3 ·
Replies
3
Views
2K