ai-station/workspaces/admin/code_20251224224804.py

31 lines
845 B
Python
Raw Permalink Normal View History

2025-12-25 14:54:33 +00:00
import sympy as sp
import matplotlib.pyplot as plt
# Definisci la tua funzione
x = sp.symbols('x')
f = x**2
# Calcola l'integrale definito da 0 a 1
integral_value, _ = sp.integrate(f, (x, 0, 1))
print(f'L integrale dell''equazione è: {integral_value}')
# Creiamo un vettore di punti per la funzione f(x)
x_values = sp.linspace(0, 1, 100)
y_values = [f.subs(x, val) for val in x_values]
# Creazione del grafico
plt.plot(x_values, y_values, label='f(x)')
plt.title('Grafico della funzione f(x)')
plt.xlabel('x')
plt.ylabel('y')
# Calcola l'area sotto la curva
area_under_curve = sp.integrate(f, (x, 0, 1))
plt.fill_between(x_values, y_values, where=[f.subs(x, val) >= 0 for val in x_values], color='gray', alpha=0.5)
plt.text(0.5, 0.25, f'Area sotto la curva: {area_under_curve}', fontsize=12)
# Mostra il grafico
plt.legend()
plt.show()