Maker Pro
Maker Pro

"Logic" Problem

J

Jim Thompson

PSpice Simulation Problem:

I have a (decimal) parameter (P) that varies from 1 thru 18 in steps
of 1.

With only IF-THEN-ELSE, AND (&), OR (|) and Algebraic operator
capabilities, how do I most compactly separate the following events:

P = 1 or 4 or 7 or 10 or 13 or 16

P = 2 or 5 or 8 or 11 or 14 or 17

P = 3 or 6 or 9 or 12 or 15 or 18

Thanks!

...Jim Thompson
 
T

Tim Wescott

Jim said:
PSpice Simulation Problem:

I have a (decimal) parameter (P) that varies from 1 thru 18 in steps
of 1.

With only IF-THEN-ELSE, AND (&), OR (|) and Algebraic operator
capabilities, how do I most compactly separate the following events:

P = 1 or 4 or 7 or 10 or 13 or 16

P = 2 or 5 or 8 or 11 or 14 or 17

P = 3 or 6 or 9 or 12 or 15 or 18

Thanks!

...Jim Thompson

In C your code would be most compact with

if (P%3 == 0) ... // 3, 6, 9, etc
if (P%3 == 1) ... // 1, 4, etc
if (P%3 == 2) ... // 2, 5, etc

I don't know if PSpice has a MOD operator (% in C), but you might want
to check.
 
J

Jim Thompson

In C your code would be most compact with

if (P%3 == 0) ... // 3, 6, 9, etc
if (P%3 == 1) ... // 1, 4, etc
if (P%3 == 2) ... // 2, 5, etc

I don't know if PSpice has a MOD operator (% in C), but you might want
to check.

That's what I first thought of too, unfortunately PSpice does not have
the MOD operator :-(

...Jim Thompson
 
R

Rene Tschaggelar

Jim said:
PSpice Simulation Problem:

I have a (decimal) parameter (P) that varies from 1 thru 18 in steps
of 1.

With only IF-THEN-ELSE, AND (&), OR (|) and Algebraic operator
capabilities, how do I most compactly separate the following events:

P = 1 or 4 or 7 or 10 or 13 or 16

P = 2 or 5 or 8 or 11 or 14 or 17

P = 3 or 6 or 9 or 12 or 15 or 18

(P-1) modulo 3

modulo, in this case means discard the upper bits.

Rene
 
J

Jim Thompson

In C your code would be most compact with

if (P%3 == 0) ... // 3, 6, 9, etc
if (P%3 == 1) ... // 1, 4, etc
if (P%3 == 2) ... // 2, 5, etc

I don't know if PSpice has a MOD operator (% in C), but you might want
to check.

You CAN build your own "functions" in PSpice. How would you
accomplish MOD using other operators?

...Jim Thompson
 
T

Tim Wescott

Jim said:
You CAN build your own "functions" in PSpice. How would you
accomplish MOD using other operators?

...Jim Thompson

x mod y = x - y * floor(x / y).

This assumes that you have a 'floor' function. If it's all integer
arithmetic you're in luck, as x / y generally returns an integer equal
to floor(x / y).
 
T

Tim Wescott

Rene said:
(P-1) modulo 3

modulo, in this case means discard the upper bits.

Rene

Or would, if 3 were an integer exponential of 2. Since it isn't you
have to use a real modulo function of some sort.
 
J

Jan Panteltje

PSpice Simulation Problem:

I have a (decimal) parameter (P) that varies from 1 thru 18 in steps
of 1.

With only IF-THEN-ELSE, AND (&), OR (|) and Algebraic operator
capabilities, how do I most compactly separate the following events:

P = 1 or 4 or 7 or 10 or 13 or 16

P = 2 or 5 or 8 or 11 or 14 or 17

P = 3 or 6 or 9 or 12 or 15 or 18

Thanks!

a = input;
b = 0;
for(i = 0; i < 6; i++)
{
if(a == (1 + b) ) result = RED
if(a == (2 + b) ) result = GREEN
if(a == (3 + b) ) result = BLEU

b = b + 3;
}

That will be $59.50 ex tax.
For testing it I charge 150$ / hour.
JP
 
J

Jan Panteltje

In C your code would be most compact with

if (P%3 == 0) ... // 3, 6, 9, etc
if (P%3 == 1) ... // 1, 4, etc
if (P%3 == 2) ... // 2, 5, etc
Shit better then mine :)
JP
 
J

Jan Panteltje

This speeds it up a bit, as it exits the loop immediatly
if a match is found:

a = input;
b = 0;
for(i = 0; i < 6; i++)
{
if(a == (1 + b) ) {result = RED; break;}
if(a == (2 + b) ) {result = GREEN; break;}
if(a == (3 + b) ) {result = BLEU; break;}

b = b + 3;
}

JP
 
J

Jim Thompson

In C your code would be most compact with

if (P%3 == 0) ... // 3, 6, 9, etc
if (P%3 == 1) ... // 1, 4, etc
if (P%3 == 2) ... // 2, 5, etc

I don't know if PSpice has a MOD operator (% in C), but you might want
to check.

Tim, Thanks for jogging my memory. You caused me to recall that my
oldest son had written some functions for me. Searching my hard-drive
found them ;-)

*
..FUNC FRACT(X) {(ATAN(TAN(((X+1e-11)-0.5)*PI))/PI+0.5)}
..FUNC TRUNC(X) {((X)-FRACT(X))}
..FUNC ROUND(X) {(TRUNC((X)+0.5))}
..FUNC BIT(X,Y) {(SGN(X-(2**Y)+0.1)+1)/2}
..FUNC MODULO(X,MOD) {(FRACT(X/MOD))*MOD}
..PARAM PI = 3.141593
*

...Jim Thompson
 
B

Beau Schwabe

This speeds it up a bit, as it exits the loop immediatly
if a match is found:

a = input;
b = 0;
for(i = 0; i < 6; i++)
{
if(a == (1 + b) ) {result = RED; break;}
if(a == (2 + b) ) {result = GREEN; break;}
if(a == (3 + b) ) {result = BLEU; break;}

b = b + 3;
}

JP

Why loop in the first place?

IF(N+2)/3 = INT((N+2)/3) THEN Group=1
IF(N+1)/3 = INT((N+1)/3) THEN Group=2
IF(N+0)/3 = INT((N+0)/3) THEN Group=3

in some programming languages you can invert the
backslash to get the same result as above...

IF(N+2)/3 = (N+2)\3 THEN Group=1
IF(N+1)/3 = (N+1)\3 THEN Group=2
IF(N+0)/3 = (N+0)\3 THEN Group=3
 
J

Jan Panteltje

Why loop in the first place?

IF(N+2)/3 = INT((N+2)/3) THEN Group=1
IF(N+1)/3 = INT((N+1)/3) THEN Group=2
IF(N+0)/3 = INT((N+0)/3) THEN Group=3
Clever!
Does he have INT?
JP
 
B

Beau Schwabe

Clever!
Does he have INT?
JP

As originally stated...

"With only IF-THEN-ELSE, AND (&), OR (|) and Algebraic operator
capabilities"

....With this I would imagine a relatively simple function such as
INT would be available.
 
J

Jan Panteltje

As originally stated...

"With only IF-THEN-ELSE, AND (&), OR (|) and Algebraic operator
capabilities"

...With this I would imagine a relatively simple function such as
INT would be available.
yes, but he did no thave modulus either...
JP
 
Top