"Algebraic" IF Statement Evaluation

I need to evaluate...

IF(t,1,0) (If t is true, output 1, if t is false, output 0 (numeric), t may be something like V11 >= 7, for example)

BUT I have no IF statement handling capability at this level of a simulation.

I do have algebraic capability.

Is there some cute way to do this algebraically?

...Jim Thompson

--
| James E.Thompson, P.E.                           |    mens     |
| Analog Innovations, Inc.                         |     et      |
 Click to see the full signature
Reply to
Jim Thompson
Loading thread data ...

X=int(V11/7) X/X

Reply to
qrus19

gah! messed that up :S

Reply to
qrus19

For your example, V11>=3D7:

(abs(V11-7))/(V11-7) will be +1 for V11>7, -1 for V11

Reply to
Tim Shoppa

t=X/X

This will sorta work, but if x is 0 then you'll probably get errors, to a human it's the 0/0 = 1 thing not having used your emulator I can't be sure what'll happen of how to treat an error like this.

Reply to
qrus19

I don't have INT available, I do have ABS and some trig functions

...Jim Thompson

--
| James E.Thompson, P.E.                           |    mens     |
| Analog Innovations, Inc.                         |     et      |
 Click to see the full signature
Reply to
Jim Thompson

That's what I came up with, except I inserted a small "delta" (smaller than my step size) to avoid 0/0. I was hoping for something more compact :-(

...Jim Thompson

--
| James E.Thompson, P.E.                           |    mens     |
| Analog Innovations, Inc.                         |     et      |
 Click to see the full signature
Reply to
Jim Thompson

Do you have a unit step function (u(x)) available?

--
Paul Hovnanian  paul@hovnanian.com
----------------------------------------------------------------------
 Click to see the full signature
Reply to
Paul Hovnanian P.E.

I don't have function SGN :-(

...Jim Thompson

--
| James E.Thompson, P.E.                           |    mens     |
| Analog Innovations, Inc.                         |     et      |
 Click to see the full signature
Reply to
Jim Thompson

(1+sgn(V11-7))/2 ?

Reply to
Spehro Pefhany

y = V11 -7

(abs(y) + y)/(2*y)

Reply to
Spehro Pefhany

P.S. If you want avoid awkward situations very near y == 0 you could do

(abs(y) + y)/(2* abs(y) + e)

where e is a very small positive number

Reply to
Spehro Pefhany

are there any operators or functions that can give a different mumeric result depending on the truth of the input.

many systems have false as 0 and true as 1 (or less common -1)

else maybe something like (sgn( sgn(V11-7) *2 +1 ) + 1 ) /2

Reply to
Jasen Betts

ABS has an intrinsic "if" that can do it. Spehro showed the method.

Reply to
Tom Del Rosso

Use PostScript for your simulation, of course.

with t on stack, {1}{0} ifelse

formatting link

--
Many thanks,

Don Lancaster                          voice phone: (928)428-4073
 Click to see the full signature
Reply to
Don Lancaster

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.