# Can you get this Simcon program to work?

**URL:** <http://discourse.iapct.org/t/can-you-get-this-simcon-program-to-work/2315>\
**Category:** CSG2002\
**Created:** [July 6, 2002, 3:12pm UTC](http://discourse.iapct.org/t/can-you-get-this-simcon-program-to-work/2315 "2002-07-06T15:12:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bill\_Powers1](http://discourse.iapct.org/letter_avatar_proxy/v4/letter/b/8e7dd6/32.png) [@Bill\_Powers1](http://discourse.iapct.org/u/Bill_Powers1)\
**Post date:** [July 6, 2002, 3:12pm UTC](http://discourse.iapct.org/t/can-you-get-this-simcon-program-to-work/2315/1 "2002-07-06T15:12:22Z")

</div>

[From Bill Powers (2002.07.06.0853 MDT)]

David Goldstein (2002.07.06) --

> Bill,  
> In part IV of the primer, there is a program called Effect of nonlinear  
> feedback factor.
> 
> I can't get this to work. I copied the program correctly.

Attached is the corrected version of part 4. The text version of the  
program was different from the .inp file included with the original  
program. An Amplifier statement lacked the final number that specifies the  
time constant.

I can see that SimPCT needs better error handling. When a statement  
contains a syntax error, that line of code should be noted and control  
should be returned to the editor so the mistake can be corrected. The  
reason the program simply exited was the syntax error, but there was  
nothing to indicate what was wrong. Also, when the numbers were incorrect  
the control system ran away and there was an arithmetic error -- and that,  
too, resulted in exiting with no indication of what was wrong.

Wolfgang, on reviewing Simcon 4.5, expressed horror at the code. I think  
he's just showing that he is a Big Bad Master Programmer -- it looked fine  
to me, though it does need some work (see above). I suppose a more advanced  
version would be technically better C programming, but this, as far as I'm  
concerned, would be casting pearls before swine. I don't mean all you  
folks, I mean me. C programmers, trying to impress each other, can write  
code that is so tight and perfect that I can't understand it at all. That  
defeats the purpose, in my opinion, which is to TEACH something to people,  
first of all to me. Baby steps, Wolfgang, PLEASE.

Best,

Bill P.

> What happens is that after I press return, the screen goes dark for a  
> while, and instead of showing the graphs, returns to the desk top.
> 
> Other programs work, so I know it is not the general setup.
> 
> Any ideas?
> 
> David

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Introduction to perceptual control theory, Part IV

Let's set up a simple control system to establish a baseline behavior,  
and then see what happens when we make the output function severely  
nonlinear. After that, we will see what happens when delays are  
introduced in the loop.

The baseline system is shown by the following program, in a file called  
primer4a.inp:

> **···**
>
> At 04:27 AM 7/6/2002, you wrote:  
> ----------------------------------------------------------  
> title Linear feedback factor  
> time 6.4 0.01  
> temp0 generator random 0.05 0.05  
> qd summator temp0 10.0  
> sr generator wave 0.0 0.0 3.2 50.0 6.4 0.0  
> se comparator sr sp  
> qo amplifier se 0.0 500.0 10.0  
> qc summator qo 1.0 qd 1.0  
> sp summator qc 1.0  
> group qc sp se qo  
> print qc se qo qd sr  
> plot
> 
> Explanation:
> 
> The disturbing quantity qd is now created by a random generator with two  
> stages of smoothing; each stage has a time constant of 0.05 sec. The  
> temporary variable is used so we can scale up the disturbance in the  
> following program line.
> 
> The reference signal sr is produced by a wave generator. The waveform  
> rises uniformly for the first half of the plot, then declines uniformly  
> to the end of the plot.
> 
> The comparator receives the perceptual signal and the reference signal  
> waveform, and the error signal se is the imput to an amplifier (rather  
> than an integrator as in Primer 3).
> 
> The amplifier amplifies the error signal by 500 times, with a time  
> constant of 10 seconds. Its output is initialized to zero.
> 
> The controlled quantity qc is the sum of the disturbance qd and the  
> output qo, each weighted by 1.0. The perceptual signal sp is numerically  
> equal to the controlled quantity.
> 
> The variables qc, sp, se, and qo are grouped so that the delay around the  
> loop is just one iteration, or 0.01 sec.
> 
> We plot the controlled quantity qc, the error signal se, the output  
> quantity qo, the disturbing quantity qd, and the reference signal sr.  
> --------------------------------------------------------------  
> Run the program. The usual relationships appear: the output quantity and  
> the disturbance produce variations in the controlled quantity that make  
> it remain near the changing value of the reference signal. The  
> disturbance contains a lot of high-frequency components, which we see as  
> slight rapid variations of the controlled quantity around the reference  
> signal's magnitude. Remember that since the input function is a  
> multiplier of 1, the controlled quantity trace also represents the  
> perceptual signal.
> 
> The error signal remains nearly zero, the high-frequency variations being  
> small in comparison with the range of the reference signal.
> 
> This program contains a random generator. There is an advantage here to  
> having your editor integrated with Simcon, because if you enter the  
> editor (by pressing the space bar twice) and leave it without changing  
> anything, the same program will run again but the random generator will  
> create a new pattern of disturbances. So by repeatedly running the  
> program you can see that the controlled quantity always behaves very  
> nearly as the reference signal specifies, while the output quantity, the  
> action of the system, is different every time. This is an excellent way  
> to convince yourself that controlling the input to the control system  
> does not mean producing the same pattern of output actions every time.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The effect of a nonlinearity in the output function
> 
> One of the myths about control systems that you will find in the  
> literature of psychology is that control models have to be linear,  
> whereas the real system contains nonlinearities that can't be handled by  
> a control system. We will now insert a nonlinearity into the output  
> function, putting in a function of the form x^3 + ax in series with the  
> integrator. This function preserves the sign of x, but changes slope with  
> the magnitude of x.
> 
> Here is the program, primer4b.inp:
> 
> ---------------------------------------------------------------  
> title Effect of nonlinear feedback factor  
> time 6.4 0.01  
> temp0 generator random 0.05 0.05  
> qd summator temp0 5.0  
> sr generator wave 0.0 0.0 3.2 50.0 6.4 0.0  
> one const 1.0 # \< ==============  
> se comparator sr sp  
> temp1 amplifier se 1.0 1.0 1.0 # \<===============  
> temp2 mult temp1 temp1 # \<===============  
> temp3 summator temp2 1.0 one 500.0 # \<===============  
> temp4 mult temp1 temp3 # \<===============  
> qo summator temp4 0.1 # \<===============  
> qc summator qo 1.0 qd 1.0  
> sp summator qc 1.0  
> group qc sp se temp1 temp2 temp3 temp4 qo # \<===============  
> print qc se qo qd sr  
> plot
> 
> Explanation:
> 
> The lines marked with arrows are new or changed.
> 
> Temp1 is the output of the same amplifier we used before, but with a gain  
> factor of 1.0 instead of 50.0. The gain is made up by the following  
> functions.
> 
> Temp2 is the output of a multiplier, both inputs of which are Temp1. Thus  
> temp2 is the square of temp1.
> 
> We add a constant of 500 to the output of the squaring multiplier, to  
> produce Temp3.
> 
> Temp4 is the output of a second multiplier, which receives temp1 and 500  
> + temp1^2. The output, temp4, is thus
> 
> temp1 \* (temp1^2 + 500), or temp1^3 + 500\*temp1
> 
> This result, multiplied by 0.1, becomes the new output quantity of the  
> control system, qo. The rest of the control system is the same as above.
> 
> All the variables in the loop are grouped.  
> ---------------------------------------------------------------  
> Run the program. If you have difficulty seeing any difference between the  
> results of primer4b.inp and those of primer4a.inp, the point of this  
> demonstration has been made.
> 
> The slope of the new nonlinear output function's amplification factor  
> varies over a range of about 50 to 1 as the output goes from 0 to maximum  
> in either direction. As you can see, the system still keeps the error  
> signal near to zero, and the controlled quantity near the level specified  
> by the changing reference signal. There is little difference in the  
> relationship between the output and the disturbance. This rather drastic  
> nonlinearity makes almost no discernible difference in the ability of the  
> control system to carry out its purpose.
> 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The effect of a time-lag
> 
> Another myth is that time-lags in the nervous system mean that control  
> processes would be unstable unless the amount of feedback is greatly  
> reduced, leading to poor control. We will now return to the basic form  
> of primer4a.inp, and put in a delay. We will put the delay into the input  
> function; you might like to experiment with putting it in the output or  
> the environment, or in several places. The program is now primer4c.inp.
> 
> --------------------------------------------------------------  
> title Linear feedback factor with delay  
> time 12.0 0.01  
> #temp0 generator random 0.3 0.3 0.3  
> #qd summator temp0 40.0  
> qd generator puls 2.0 6.0 40.0  
> sr generator wave 0.0 0.0 4.0 50.0 8.0 50.0 12.4 0.0  
> se comparator sr sp  
> qo amplifier se 0.0 800.0 400.0  
> qc summator qo 1.0 qd 1.0  
> temp1 summator qc 1.0  
> sp delay temp1 20  
> group se qo qc  
> print qc qd sr  
> plot
> 
> Explanation:
> 
> The total duration of the run is now 12 seconds, with dt still set to  
> 0.01 sec.
> 
> The disturbance is now a pulse that rises at time 2.0 to 40 units, and  
> falls back to zero at time 6.0. Note that the previous two lines have  
> been "commented out": the # mark turns a line into a comment that is  
> ignored when the program is run. We will use these two lines later.
> 
> The reference signal is the output of a wave generator. It rises from 0  
> to 50 during the first 4 seconds, remains constant at 50 until time 8.0,  
> then falls to zero over the remaining 4 seconds.
> 
> The gain factor of the amplifier has been raised to 800 (!) and the time  
> constant is set to 400 seconds.
> 
> The summator that previously created the perceptual signal sp now  
> produces a temporary variable temp1.
> 
> The perceptual signal sp now comes through a delay of 0.2 seconds from  
> temp1. This is accomplished by a delay of 20 iterations, with each  
> iteration taking 0.01 sec (determined by the "time" directive in the  
> second line).
> 
> Note that the perceptual signal sp is not included in the grouping,  
> because it is being deliberately delayed.  
> --------------------------------------------------------------  
> Run the program.
> 
> Initially, the controlled variable rises in parallel with the rising  
> reference signal, lagging it by about 0.2 seconds because of the delay  
> in the perceptual function. Then the disturbance suddenly appears with  
> an amplitude of 40 units. If you look closely, you will see that the  
> controlled variable is driven positive by the same amount and continues  
> to rise for about 0.2 more seconds. Then the control system senses an  
> error and the output quantity begins to change. The controlled variable  
> is restored to the original path, rising along with the reference signal.
> 
> The reference signal stops rising while the disturbance is still present.  
> The controlled quantity quickly catches up and exactly matches the  
> reference signal. Then the disturbance suddenly disappears. The output  
> quantity, which was cancelling the disturbance, is still at its former  
> magnitude for a moment, so the controlled quantity suddenly goes  
> negative. After remaining at a low value for about 0.2 seconds, it rises  
> again to match the reference signal, and follows the reference signal for  
> the remainder of the plot (with a slight delay due to the delay in the  
> perceptual function).
> 
> What we see here is a classical "reaction time" after the disturbance  
> appears and again when it disappears. As long as the reference signal or  
> the disturbance is changing, the output will lag a little behind (or a  
> lot, if the change is extremely rapid) and there will be some error due  
> to the lag.
> 
> As mentioned, a widely prevalent myth is that a control system containing  
> a delay or reaction time will necessarily become unstable. As we can see  
> here, this control system, which has a very large amplification factor  
> in its output function, is not at all unstable. It reacts after a lag by  
> restoring the controlled quantity to its reference level, very closely  
> while the reference signal is changing, and exactly when the reference  
> signal levels off.
> 
> This result is achieved by adjusting the time constant of the output  
> function. You can experiment with it, reducing it and increasing it to  
> see the effects. If that time constant is too short the control system  
> will indeed begin to show signs of instability. But if it is long enough,  
> the delay effects are nicely compensated, and the system reacts just as  
> fast as a system without feedback could react. It also controls a great  
> deal better when disturbances act on the controlled quantity than a  
> system without feedback could control. Notice, by the way, that even  
> though the time constant of the output function is 400 seconds, the time  
> constant for restoration of the controlled quantity to its former value  
> is only a few tenths of a second, following the lag. The overall dynamic  
> characteristics of a control system do not reflect the dynamic  
> characteristics of its components.
> 
> The above program was set up in the way a typical stimulus-response  
> experiment would be designed, with the disturbance appearing and  
> disappearing very suddenly. We can see behavior in more normal  
> circumstances by changing the disturbance to a smooth random wave as in  
> the previous programs. Change the lines near the beginning by removing  
> the two # marks and adding one to the following line, like this:
> 
> temp0 generator random 0.3 0.3 0.3  
> qd summator temp0 40.0  
> #qd generator puls 2.0 6.0 40.0
> 
> We have turned off the pulse disturbance and substituted a random one.  
> Now we use a three-stage filter and a time constant of 0.3 seconds in  
> each stage, making the disturbance smoother in recognition of the fact  
> that a control system with a delay can't oppose disturbances with too  
> wide a bandwidth.
> 
> Running the program, we now see that the controlled quantity follows the  
> reference signal while the disturbance varies. This is still a rather  
> severe disturbance for a control system having a lag of 0.2 seconds, but  
> it is clear that the controlled quantity is being determined by the  
> reference signal. This situation is about the same as for a human  
> hand-eye tracking experiment in which the target is moving irregularly  
> at a speed near the limit of what a human being can track. A model of  
> this form can be matched to actual human performance by adjusting the  
> perceptual time delay, the amplification factor, and the amplifier time  
> constant. The output quantity variations will match the handle movements  
> of the real human subject within about 3 to 5 per cent RMS. The optimal  
> lag in the model turns out to be about 0.16 sec. This is the lag  
> associated with pursuit tracking of objects by the eye, not saccadic eye  
> movements.
> 
> Control is certainly not perfect under these circumstances. But a human  
> being presented with the same disturbance also controls imperfectly, and  
> the model matches those imperfections quite closely. A lag in the system,  
> far from preventing the model from working, is required in order to  
> achieve the best match between the model's behavior and real behavior --  
> the best match with the imperfections of control in the real human  
> control system.
