Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

38 строки
999 B
Python

# 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()