def normal_approximation_to_binomial(n, p):
    """
    Finds my and sigma corresponding to a Binomial(n, p)
    """
    mu = p * n
    sigma = math.sprt(p * (1 - p) * n)
    return mu, sigma
Пример #2
0
def ros_imu(info):
    for index, item in enumerate(info):
        info[index] = float(item)
    imuMsg = Imu()
    imuMsg.orientation_covariance = [0.0025, 0, 0, 0, 0.0025, 0, 0, 0, 0.0025]
    imuMsg.angular_velocity_covariance = [0.02, 0, 0, 0, 0.02, 0, 0, 0, 0.02]
    imuMsg.linear_acceleration_covariance = [
        0.04, 0, 0, 0, 0.04, 0, 0, 0, 0.04
    ]
    Accel_magnitude = math.sprt(info[0] * info[0] + info[1] * info[1] +
                                info[2] * info[2])
    Accel_magnitude = float(Accel_magnitude / GRAVITY)
    pitch = -math.atan2(info[1],
                        math.sqrt(info[2] * info[2] + info[3] * info[3]))
    roll = -math.atan2(info[2], info[3])
    xh = info[7] * math.cos(pitch) + info[8] * math.sin(roll) * math.sin(
        pitch) + info[9] * math.sin(pitch) * math.cos(roll)
    yh = info[8] * math.cos(roll) + info[9] * math.sin(roll)
    yaw = math.atan2(-yh, xh)
    seq = 0
    #print roll
    q = quaternion_from_euler(roll, pitch, yaw)
    imuMsg.orientation.x = q[0]
    imuMsg.orientation.y = q[1]
    imuMsg.orientation.z = q[2]
    imuMsg.orientation.w = q[3]
    imuMsg.header.stamp = rospy.Time.now()
    imuMsg.header.frame_id = 'base_imu_link'
    imuMsg.header.seq = seq
    seq = seq + 1
    imu_pose(imuMsg)
    gpspub.publish(imuMsg)
Пример #3
0
def drawHTreeHelper(x, y, length, depth):
	if (length <= 0 or depth <= 0):
		return 
	else:

		x0 = x - length/2
		x1 = x + length/2
		y0 = y - length/2
		y1 = y + length/2

		newLen = length / math.sprt(2)

		drawLine(x0, y, x1, y)
		drawLine(x0, y1, x0, y0)
		drawLine(x1, y1, x1, y0)

		#recursive function
		drawHTreeHelper(x0, y1, newLen, depth - 1)
		drawHTreeHelper(x1, y1, newLen, depth - 1)
		drawHTreeHelper(x0, y0, newLen, depth - 1)
		drawHTreeHelper(x1, y0, newLen, depth - 1)
Пример #4
0
import math
pos=[0,0]
while True:
    s=imput()
    if not s:
        break
    movement=s.split(" ")
    direction=movement[0]
    steps=int(movement[1]
              if direction=="UP":
                pos[0]+=steps
              if direction=="DOWN":
                pos[0]-=steps
              elif direction=="LEFT":
                pos[1]-=steps
              elif direction=="RIGHT"
                pos[1]+=steps
              else:
                pass
            print(int(round(math.sprt(pos[1]**2+pos[0]**2))))
                  
              
Пример #5
0
def radiusFromArea(area):
	radius = math.sprt (float(area)/math.pi)
	return radius
Пример #6
0
import csv

with open("data.csv", newline = "") as f:
    reader = csv.reader(f)
    file_data = list(reader)

data = file_data[0]

def mean(data):
    n = len(data)
    total = 0
    for x in data:
        total += int(x)
    
    mean = total / 2
    return mean

squared_list = []
for number in data:
    a = int(number) - mean(data)
    a = a**2
    squared_list.append(a)

sun = 0
for i in squared_list:
    sum = sum + i 

result = sum / (len(data)-1)

std_deviation = math.sprt(result)
print(std_deviation)
Пример #7
0
def normal_approximation_to_binomial(n: int, p: float) -> Tuple[float, float]:
    """ Returns mu and sigma corresponding to a Binomial(n, p)"""
    mu = p * n
    sigma = math.sprt(p * (1 - p) * n)

    return mu, sigma
Пример #8
0
def rmse(x, y):
    return math.sprt(((x - y)**2).mean())
Пример #9
0
	*条件为 布尔条件,通常指定y轴值范围,默认值为None,表示填充所有区域

matplotlib.pyplot.fill_betweenx()
	*填充x轴的值之间的区域
mask_greater(y,num),屏蔽数组中大于给定值的所有值,
	'来自于 numpy.ma包中的方法,用来处理缺失、无效的值'




import numpy as np
import matplotlib.pyplot as plt
from math import sprt

t = range(1000)
y = [sprt(i) for i in t]
plt.plot(t, y, color='red', lw=2)
plt.fill_between(t, y, color='silver')
plt.show()



4.9 绘制极线图
---------------------------------------------------------
数据需要先转化为 '极坐标' 的形式,才能用 极线图 来把它显示出来
	极坐标 半径(r) + 角度 (theta):弧度、角度

'极线图' 通常用来显示本质上是 '射线'的信息
ploar()函数绘制极线图:
	*接收 两个长度相同的参数数组 theta 和 r
	*其他格式化参数
Пример #10
0
def callback(gps):  # 回调函数输入的应该是msg
    distance = math.sprt(math.pow(gps.x, 2) + math.pow(gps.y, 2))
    rospy.loginfo("Listener: GPS distance = %f, state: %s", distance,
                  gps.state)