# Update a vector in a for loop

• Mathematica
Gold Member
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]

## Answers and Replies

Related MATLAB, Maple, Mathematica, LaTeX News on Phys.org
RPinPA
Homework Helper
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}?

Dale
Mentor
I have tried this but it's not working.
What do you mean by “it’s not working”? What happens?

jedishrfu
Mentor
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?

DrClaude
Mentor
\[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 λ = Null

In[16]:= FullForm[Sqrt[2]]
Out[16]//FullForm=
Power[2, Rational[1, 2]]

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

Out[17]//FullForm=
Null

You have to instead use in the For loop
Code:
\[Lambda] = Catenate[{\[Lambda], {\[CapitalLambda]}}]; Print[\[Lambda]]

Last edited:
mfb and Dale
Gold Member
Thanks all! I would have replied a while ago but for some reason I did not receive email notifications. I have it working!