ответвлено от main/python-labs
икз
Этот коммит содержится в:
@@ -11,29 +11,29 @@
|
|||||||
>>> import os
|
>>> import os
|
||||||
>>> os.chdir('C:\\Users\\u115-07\\Desktop\\python-labs\\TEMA7')
|
>>> os.chdir('C:\\Users\\u115-07\\Desktop\\python-labs\\TEMA7')
|
||||||
>>> normal= lambda x, a, b: math.exp(-(x-a)**2/b) / math.sqrt(2 * math.pi * b)
|
>>> normal= lambda x, a, b: math.exp(-(x-a)**2/b) / math.sqrt(2 * math.pi * b)
|
||||||
def test_normal():
|
>>> def test_normal():
|
||||||
a, b = 0, 1
|
... a, b = 0, 1
|
||||||
std_dev = math.sqrt(b)
|
... std_dev = math.sqrt(b)
|
||||||
start = a - 3 * std_dev
|
... start = a - 3 * std_dev
|
||||||
end = a + 3 * std_dev
|
... end = a + 3 * std_dev
|
||||||
step = 0.2 * std_dev
|
... step = 0.2 * std_dev
|
||||||
x_values = []
|
... x_values = []
|
||||||
current = start
|
... current = start
|
||||||
while current <= end:
|
... while current <= end:
|
||||||
x_values.append(current)
|
... x_values.append(current)
|
||||||
current += step
|
... current += step
|
||||||
function_values = []
|
... function_values = []
|
||||||
for x in x_values:
|
... for x in x_values:
|
||||||
y = normal_pdf(x, a, b)
|
... y = normal_pdf(x, a, b)
|
||||||
function_values.append(y)
|
... function_values.append(y)
|
||||||
file = open('ikz.txt', 'w')
|
... file = open('ikz.txt', 'w')
|
||||||
for i in range(0, len(function_values), 2):
|
... for i in range(0, len(function_values), 2):
|
||||||
if i + 1 < len(function_values):
|
... if i + 1 < len(function_values):
|
||||||
file.write(str(function_values[i])+','+str(function_values[i+1])+'\n')
|
... file.write(str(function_values[i])+','+str(function_values[i+1])+'\n')
|
||||||
else:
|
... else:
|
||||||
file.write(str(function_values[i])+',0\n')
|
... file.write(str(function_values[i])+',0\n')
|
||||||
file.close()
|
...
|
||||||
...
|
...
|
||||||
>>> test_normal()
|
>>> test_normal()
|
||||||
|
|
||||||
4.9233388666234e-05,0.0001570512248023814
|
4.9233388666234e-05,0.0001570512248023814
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user