This notation is called the 'ternary operator.' It's sometimes used in C/C++ and supported in most other popular languages (I know Julia also uses it, for example). It's mostly a shorthand notation for an if-else statement, with the one difference that it returns a value.
The statement
x = a ? b : c
assigns the value b to x if condition a is true, else value c is assigned to x. It's equivalent to
int x;
if(a)
{
x = b;
}
else
{
x=c;
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
One, how many "transitions" can be had? Just one, "before, after"? Could "TIME" be the argument to a more complex resistor-value expression, and get an "arbitrary resistance time profile"?
Two, is the transition "smoothed" or "sharp" when you hit the timepoint in the example? Thinking about transient solution troubles.
Last edit: dick freebird 2022-09-13
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Could "TIME" be the argument to a more complex resistor-value expression, and
get an "arbitrary resistance time profile"?
Yes. Better use a TABLE then instead of a series of "IF(,,)" or ",?,:, "then.
Two, is the transition "smoothed" or "sharp" when you hit the timepoint in the example?
Thinking about transient solution troubles.
With the conditional statement it is "sharp" (because that may be the point of the simulation, study a load or input disturbance). A TABLE or PWL based expression performs linear interpolation. Using POLY() lets you control an arbitrary (amount of) derivative(s).
There are devices that are by nature discontinuous (like a switch), but at least in XSPICE these are all 'tweaked' to work with the SPICE solver.
-marcel
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
To switch the resistance during transient simulation, you may use a resistor like:
Holger, thanks for sharing. This is a slick trick.
didn't understand the part "2k : 1k" , what does it mean?
"x ? y : z" is C-like syntax for "if(x) y; else z;" or SPICE-like IF(x,y,z). It works in places where NGSPICE expects an expression.
This notation is called the 'ternary operator.' It's sometimes used in C/C++ and supported in most other popular languages (I know Julia also uses it, for example). It's mostly a shorthand notation for an if-else statement, with the one difference that it returns a value.
The statement
x = a ? b : c
assigns the value b to x if condition a is true, else value c is assigned to x. It's equivalent to
int x;
if(a)
{
x = b;
}
else
{
x=c;
}
Interesting.
A couple of questions occur to me.
One, how many "transitions" can be had? Just one, "before, after"? Could "TIME" be the argument to a more complex resistor-value expression, and get an "arbitrary resistance time profile"?
Two, is the transition "smoothed" or "sharp" when you hit the timepoint in the example? Thinking about transient solution troubles.
Last edit: dick freebird 2022-09-13
Yes. Better use a TABLE then instead of a series of "IF(,,)" or ",?,:, "then.
With the conditional statement it is "sharp" (because that may be the point of the simulation, study a load or input disturbance). A TABLE or PWL based expression performs linear interpolation. Using POLY() lets you control an arbitrary (amount of) derivative(s).
There are devices that are by nature discontinuous (like a switch), but at least in XSPICE these are all 'tweaked' to work with the SPICE solver.
-marcel