Error while updating LAMMPS variables

hi,
I wanted to generate a sequence
image

using the given equation, as i have a requirement to use the sequence in the simulation as an input every timestep sequentially
image

I have implemented the following algorithm in LAMMPS as follows
variable x atom 0
variable f atom v_x *v_x +v_x+1
variable x delete
variable x atom v_f

However there was an error “ERROR: Variable f: has a circular dependency”
Is there any straightforward way of implementing this ,please kindly help
Current Version:LAMMPS (2 Jun 2022)

Thank you
Raman

Besides the broken logic of the use of variables, the formula you have supposedly implemented is f=x^2+x+1. If I stick to the original sequence that you posted, that’s how I would do it:

# Input variables.
variable x equal 0
variable i loop 10

# Loop 
label       cycle1
print "$i $x"
variable x equal $x+2
next i
jump SELF cycle1

Which produces:

$ lmp_7Feb24 -in test5
LAMMPS (7 Feb 2024 - Update 1)
1 0
2 2
3 4
4 6
5 8
6 10
7 12
8 14
9 16
10 18

Hi,
Thanks for you reply, but my requirement is to use these variable in the simulation as an input every timestep(input to fix addforce) So i used (atom style variable) as it updates the variable every timestep as mentioned in the documentation.
I want the variable x to get updated by using variable f , subsequently variable f will be updated by using variable x and so on… until the simulation ends
please help

You are misunderstanding the whole concept of computer programming. Computers don’t reason, they follow rules, regardless of whether they make sense or not. So you cannot just expect a computer to follow some demonstration of what you want.

The biggest problem is that LAMMPS commands are executed immediately (like in a computer program). A simulation run is started when you use the “run” command then it uses the state that LAMMPS (and the definition of its variables) from that point. If you want something change in a variable during a run, you need to have some function in it that changes with the timestep like the “ramp()” function. You cannot have variable definitions changed during a run, so you need to follow the logic that is compatible with what LAMMPS has available, and not expect LAMMPS to follow your logic.

BTW: if all values are the same, you can use an equal style variable instead of an atom style variable.

Isn’t x_i just 2i?

yeah but that equation is just for simplicity, Equation might be different (depending on my research problem)