Katerina 2 недель назад
Родитель 541cfa55cb
Сommit c0d720f810

@ -0,0 +1,37 @@
# Mod1.py
import math
def calc_function(a, x):
if x == 0:
return a
return a * math.sin(x) / x
def calculate_interval(a, x_start=0.5, x_end=50, step=0.5):
results = []
x = x_start
while x <= x_end:
value = calc_function(a, x)
results.append((x, value))
x += step
return results
def write_to_file(results, filename="output.txt"):
with open(filename, 'w', encoding='utf-8') as f:
for x, val in results:
f.write(f"{val}\n")
print(f"Данные записаны в файл: {filename}")
def plot_function(results):
import matplotlib.pyplot as plt
x_vals = [item[0] for item in results]
y_vals = [item[1] for item in results]
plt.figure(figsize=(10, 5))
plt.plot(x_vals, y_vals, label="f(x) = a * sin(x) / x", color='blue')
plt.title("График функции f(x) = a * sin(x) / x")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.grid(True)
plt.legend()
plt.show()

@ -0,0 +1,24 @@
import Mod1
print("=" * 50)
print("Расчёт функции f(x) = a * sin(x) / x")
print("=" * 50)
try:
a = float(input("Введите коэффициент a: "))
filename = input("Введите имя файла ('output.txt'): ") or "output.txt"
except ValueError:
print("Ошибка ввода! Используйте числа.")
exit()
results = Mod1.calculate_interval(a)
print("\nПервые 10 значений:")
for x, val in results[:10]:
print(f" x={x:.1f}, f(x)={val:.6f}")
Mod1.write_to_file(results, filename)
print("\nОтображение графика:")
Mod1.plot_function(results)

Двоичные данные
TEMA8/test/image1.png

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 27 KiB

Двоичные данные
TEMA8/test/image2.png

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 12 KiB

@ -0,0 +1,100 @@
1.917702154416812
1.682941969615793
1.3299933154720727
0.9092974268256817
0.47877771528316515
0.0940800053732448
-0.20044755867978276
-0.3784012476539641
-0.43445783007337646
-0.3835697098652554
-0.2565601183892334
-0.09313849939964196
0.0661907655654817
0.18771045677679687
0.25013332713993036
0.24733956165584545
0.18787932061729182
0.09158188560927924
-0.015821288518275644
-0.10880422217787396
-0.16756109713746095
-0.181816401191037
-0.1522525521197267
-0.08942881966673916
-0.01061150357619211
0.06464108258871398
0.11907917430394385
0.14151533652783863
0.1289510421413356
0.08670504535428224
0.026640965411328592
-0.03598791458313316
-0.08627701119625734
-0.11310558727994786
-0.11150011491064658
-0.08344302741907512
-0.037024931726444596
0.015776548385573932
0.06210665330457447
0.09129452507276277
0.09725168724671213
0.0796814893843863
0.04387339563666941
-0.0008046644809458069
-0.043304401107600844
-0.07358438297175397
-0.08494315131739542
-0.07546486350055198
-0.0482740840706224
-0.010588140007821843
0.028161439531150453
0.05865834234458482
0.07391378438520128
0.07084266136329652
0.050853820484007106
0.019350413450562074
-0.015702150188547117
-0.045767854083652935
-0.06379873954867482
-0.06586877493952412
-0.05200834357096952
-0.026066944859552584
0.005331711472491862
0.03446416757760566
0.05439202606435881
0.06060071879437983
0.052008358219055306
0.031122510948236697
0.0033326074263724387
-0.024467581114065773
-0.04557852204010741
-0.05509882519128421
-0.05105298015642222
-0.034785845046324294
-0.010549269313944655
0.015598346247862386
0.03729738144268281
0.049425404424825015
0.049298504085821676
0.03725565802396744
0.01650129268387262
-0.007737691161205316
-0.029520971227733485
-0.0436438832340778
-0.046874658970333834
-0.038687197331562714
-0.021324851309601257
0.0008046329593369808
0.02224203674393834
0.0378179344237386
0.043894104281836065
0.0392081890282091
0.02512673481347465
0.005258430755115915
-0.01546548838459753
-0.03201061088848612
-0.04045807994239575
-0.03892867970446824
-0.027995351686209927
-0.01049499414815715
Загрузка…
Отмена
Сохранить