-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPushMePullYou_Payment.go
82 lines (56 loc) · 2.26 KB
/
PushMePullYou_Payment.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
///////////////////////////////////////////////////////////////
//
// A bistable oscillator to figure out the wave, phase relationships
//
// In this model, both sides can borrow from one another without limit
// They only see what the other seems to have, and while the sum
// of both sides is always zero, the oscillations grow unimpeded.
//
///////////////////////////////////////////////////////////////
package main
import (
"fmt"
)
const PERIOD = 100000
// ****************************************************************
func main () {
var psi1,psi2,theta1,theta2 float64
psi1 = 0
theta1=100
for t := 0; t < 10000; t++ {
//fmt.Printf("-----------------------------------------\n") // CLS
//fmt.Printf(" PSI1 THETA1 dpsi1 ; dpsi2 THETA2 PSI2\n") // CLS
//fmt.Printf("-----------------------------------------\n") // CLS
dpsi1,dtheta1 := PleaseGiveMe(psi1,theta1,psi2)
dpsi2,dtheta2 := PleaseGiveMe(psi2,theta2,psi1)
//Show(psi1,dpsi1,theta1,psi2,dpsi2,theta2)
// Exchange
psi1 = psi1 + dpsi1
psi2 = psi2 - dpsi1
theta1 = theta1 + dtheta1 //% PERIOD
//Show(psi1,dpsi1,theta1,psi2,dpsi2,theta2)
psi2 = psi2 + dpsi2
psi1 = psi1 - dpsi2
theta2 = theta2 + dtheta2 //% PERIOD
Show(psi1,dpsi1,theta1,psi2,dpsi2,theta2)
}
}
// ****************************************************************
func PleaseGiveMe(me,theta,you float64) (float64,float64) { // Please give me
// This is based on full trust, just do as we're told.
// Unless there's some limit, this can keep borrowing from
// other to produce runaway inflation
const dt = 0.01
const mass = 10 // blow up
grad := you - me // Your surplus relative to me tells me to balance you with neg feedback
// (force direction) gradient makes directionality from neighbour alone
// we assume the whole force is represented in the displacement -kx
deltaTheta := grad / mass * dt // small increments
DeltaPsi := theta * dt
return DeltaPsi, deltaTheta
}
// ****************************************************************
func Show(psi1,dpsi1,theta1,psi2,dpsi2,theta2 float64) {
fmt.Printf("%8.2f %8.2f %8.2f ----> %f\n",psi1,theta1,dpsi1,psi1+psi2)
//fmt.Printf("%8d %8d %8d\n",dpsi2,theta2,psi2)
}