Maker Pro
Maker Pro

Drawing Mathematical Blank This A.M.

J

Jim Thompson

Try thinking of it as an analogue opamp problem,
with a Vin and a Vout.

Offset Vin by -0.5, full wave rectify it, correct
for the offset.

Vout = 0.5 - ABS(Vin - 0.5).

Vin Vout

0.1 0.1
0.2 0.2
0.3 0.3
0.4 0.4
0.5 0.5
0.6 0.4
0.7 0.3
0.8 0.2
0.9 0.1
1.0 0.0

That might be the answer, BUT with NEARLY ideal diodes.

My expression, N - Round(N), works by itself, but the sharp
discontinuities cause insurmountable convergence issues.

...Jim Thompson
 
K

Ken Smith

I need to process (in PSpice) a number of the form:

Integer.Decimal

I want to report Decimal when Decimal is <= 0.5

But report -(1-Decimal) when Decimal is > 0.5

(For behavioral modeling of a PLL)

I seem to be foggy-brained this morning and can't sort it out :)

I have the following functions available:

*
.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 DIV(X,MOD) {TRUNC((X+1u)/MOD)}
.FUNC MODULO(X,MOD) {(FRACT(X/MOD))*MOD}
.FUNC INT(X) {((X)-FRACT(X))}
.PARAM PI = 3.141593

LTSpice has FLOOR built in and it is faster than using TAN to get there.
 
J

Jim Thompson

LTSpice has FLOOR built in and it is faster than using TAN to get there.

--

So?

The real issue turns out to be differentiability.

...Jim Thompson
 
R

Rich Grise

The real issue turns out to be differentiability.

Then report Decimal when Decimal is <=0.49999
*
and report (Decimal - 1) when decimal is >= .50001

and make up something clever to do at *, like report
"Changing" when 0.49999 < Decimal < 5.0001, or something.

Good Luck!
Rich
 
D

Don Taylor

Jim Thompson said:
The real issue turns out to be differentiability.

It seems that all those functions are going to have differentiability
problems.

If you have do have access to the functions used to define those then

-ATAN(K*(X-1/2))/PI+X-1/2

seems to approximate what you want and is a smooth function,
where K is a positive constant, the larger you make it the closer you
are to a sawtooth but the larger the negative spike the derivative will
have. K perhaps somewhere between 10 and 40 might serve your purposes.

Or, if you have hyperbolic tangent, or can build it from e^x, then

-TANH(K*(X-1/2))/2+X-1/2

also seems to approximate what you want and is a smooth function.

And, if I understood your earlier comment, that you wanted your
function to linearly increase for increasing x, then either of these
satisfy that, unlike x-ROUND(x) that is a sawtooth repeating over
and over and not increasing beyond x=1.
 
J

Jim Thompson

It seems that all those functions are going to have differentiability
problems.

If you have do have access to the functions used to define those then

-ATAN(K*(X-1/2))/PI+X-1/2

seems to approximate what you want and is a smooth function,
where K is a positive constant, the larger you make it the closer you
are to a sawtooth but the larger the negative spike the derivative will
have. K perhaps somewhere between 10 and 40 might serve your purposes.

Or, if you have hyperbolic tangent, or can build it from e^x, then

-TANH(K*(X-1/2))/2+X-1/2

also seems to approximate what you want and is a smooth function.

And, if I understood your earlier comment, that you wanted your
function to linearly increase for increasing x, then either of these
satisfy that, unlike x-ROUND(x) that is a sawtooth repeating over
and over and not increasing beyond x=1.

Sawtooth _repeating_ IS what I want.

But I do have TANH available.

Thanks for the pointer.

...Jim Thompson
 
K

Ken Smith

[...]
LTSpice has FLOOR built in and it is faster than using TAN to get there.

--

So?

The real issue turns out to be differentiability.


I was thinking of 2 things:

(1) The TAN fuction in not defined at PI/2. Unless the evaluator is one
of those trick ones with rules for passing +INF, -INF, and NAN along to
see if further operations fix the problem, the convergence doesn't get a
chance to continue if you happen onto that point. Even with the trick
evaluator, there could be a problem with the curve near the point where
the value overflows.

(2) Linear's spice contains "hacks". I assumed that using the FLOOR
fuction would be more likely to engage the right hack than a method that
goes through a few steps to the result.
 
H

Helmut Sennewald

Jim Thompson said:
Sawtooth _repeating_ IS what I want.

Hello Jim,
just pass the sawtooth thtough a TABLE function. You have then
the choice where SPICE interpolates betwenn 0 and 0.5-eps,
e.g. 0.49, 0.499 or however close you want go towars 0.5/-0.5.

sawtooth table-out
0.5 0
0.499 0.499
-0.499 -0.499
-0.5 0

Best Regards,
Helmut
 
J

Jim Thompson

Ah. Well then I think this might do what you are looking for

-TANH(K*(FRACT(X)-1/2))/2+FRACT(X)-1/2


Happy to help with math puzzles

Aha! Sweet! Thanks! Nice and smooth! Now I'll try closing the loop
:)

...Jim Thompson
 
J

Jim Thompson

[snip]
Ah. Well then I think this might do what you are looking for

-TANH(K*(FRACT(X)-1/2))/2+FRACT(X)-1/2


Happy to help with math puzzles

Aha! Sweet! Thanks! Nice and smooth! Now I'll try closing the loop
:)

...Jim Thompson

Looks like the ATAN in function FRACT makes it blow up inside the
feedback loop :-(

...Jim Thompson
 
Top