CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download
Project: test
Views: 91872
1
# -*- coding: utf-8 -*-
2
"""
3
Created on Wed Apr 30 10:35:19 2014
4
5
@author: rlabbe
6
"""
7
import numpy.random as random
8
import math
9
10
class dog_sensor(object):
11
def __init__(self, x0 = 0, motion=1, noise=0.0):
12
self.x = x0
13
self.motion = motion
14
self.noise = math.sqrt(noise)
15
16
def sense(self):
17
self.x = self.x + self.motion
18
self.x += random.randn() * self.noise
19
return self.x
20
21
22
def measure_dog ():
23
if not hasattr(measure_dog, "x"):
24
measure_dog.x = 0
25
measure_dog.motion = 1
26
27
28
if __name__ == '__main__':
29
30
dog = dog_sensor(noise = 1)
31
for i in range(10):
32
print (dog.sense())
33
34
35
36
37
38