Electronic – IF statement on LTspice


I would like to create a variable resistor as following:

R2=1 if i(R2)<1
R2=2 if 1<i(R2)<10
R2=3 if i(R2)>10

I know that the syntax is:


What if I have three intervals?

The .asc file and the IF statement law is also shown below.

What is the correct syntax to do that?

Best Answer

Then you can either

  1. Create a B source with the conditional statements and an additional signal (which is useful for debugging)

  2. Nest the if statements