0
import matplotlib.pyplot as plt import numpy as np x=np.linspace(-5,5,100) plt.plot(x,np.sin(x)) plt.xlabel("axe des absesse")
He guys . Please where I can execute like this cods it's about graphs and the numpy library
9 odpowiedzi
0
import numpy as np
import matplotlib.pyplot as plt
# Values for x1 (chairs)
x1 = np.linspace(0, 100, 200)
# Wood constraint: 5x1 + 10x2 <= 500
x2_wood = (500 - 5*x1) / 10
# Metal constraint: 2x1 + 5x2 <= 300
x2_metal = (300 - 2*x1) / 5
# Plot the constraints
plt.figure(figsize=(8, 6))
plt.plot(x1, x2_wood, label="Wood constraint (5x1 + 10x2 ≤ 500)", color="blue")
plt.plot(x1, x2_metal, label="Metal constraint (2x1 + 5x2 ≤ 300)", color="red")
# Fill feasible region (the region where both constraints are satisfied)
plt.fill_between(x1, np.minimum(x2_wood, x2_metal), color="grey", alpha=0.3)
# Labels and title
plt.xlim(0, 100)
plt.ylim(0, 60)
plt.xlabel("Chairs (x1)")
plt.ylabel("Tables (x2)")
plt.title("Feasible Region for Furniture Production")
# Highlight the intersection of the two lines
plt.legend()
plt.grid(True)
plt.show()
+ 1
In ms visual studio code.
https://code.visualstudio.com/Download
+ 1
Thanks
+ 1
I think this can also run on sololearn.
You can also try online platforms like:
- kaggle
- Google colab notebooks
0
Grafik chizma
0
import matplotlib.pyplot as plt
import numpy as np
Y = np.linspace(0, 200, 100)
S = 0.25 * Y - 10
I = np.full_like(Y, 20)
C = Y - S
plt.figure(figsize=(10,6))
plt.plot(Y, S, label='Fungsi Saving: S=0.25Y-10', color='blue')
plt.axhline(y=20, color='red', linestyle='--', label='Investasi: I=20')
plt.plot(Y, C, label='Fungsi Konsumsi: C=Y-S', color='green')
plt.title('Grafik Fungsi Saving dan Konsumsi')
plt.xlabel('Pendapatan Nasional (Y)')
plt.ylabel('Saving (S) dan Konsumsi (C)')
plt.legend()
plt.grid()
plt.show()
0
# (Simulação do que seria gerado com uma ferramenta gráfica)
import numpy as np
import matplotlib.pyplot as plt
# Dados
t_values = np.array([0.0, 0.2, 0.3, 0.5, 0.8, 1.0, 1.4, 1.8, 2.0, 3.0])
Vc_points = np.array([5.0, 3.27, 2.64, 1.73, 0.91, 0.595, 0.255, 0.109, 0.071, 0.009])
# Geração de pontos para a curva exponencial
t_curve = np.linspace(0, 3, 300)
Vc_curve = 5 * np.exp(-t_curve / 0.47)
# Plot
plt.figure(figsize=(8, 5))
plt.plot(t_curve, Vc_curve, label=r'$V_C(t)=5e^{-t/0.47}#x27;, color='blue', linewidth=2)
plt.scatter(t_values, Vc_points, color='red', zorder=5, label='Pontos calculados')
plt.title("Descarregamento do Capacitor (Circuito RC)")
plt.xlabel("Tempo (s)")
plt.ylabel("Tensão (V)")
plt.xticks(np.arange(0, 3.1, 0.5))
plt.yticks(np.arange(0, 5.5, 0.5))
plt.grid(True)
plt.legend()
plt.tight_layout()
plt.show()
0
import matplotlib.pyplot as plt
import numpy as np
def draw_cau1_image():
A = np.array([0, 0])
B = np.array([0, 4])
C = np.array([6, 0])
AB = np.linalg.norm(B - A)
BC = C - B
BC_unit = BC / np.linalg.norm(BC)
M = B + AB * BC_unit
def foot_of_perpendicular(P, A, B):
AP = P - A
AB = B - A
proj_len = np.dot(AP, AB) / np.dot(AB, AB)
proj = A + proj_len * AB
return proj
H = foot_of_perpendicular(B, A, M)
def line_intersection(P1, P2, Q1, Q2):
A1, B1 = P1, P2
A2, B2 = Q1, Q2
a1 = B1[1] - A1[1]
b1 = A1[0] - B1[0]
c1 = a1 * A1[0] + b1 * A1[1]
a2 = B2[1] - A2[1]
b2 = A2[0] - B2[0]
c2 = a2 * A2[0] + b2 * A2[1]
determinant = a1 * b2 - a2 * b1
if determinant == 0:
return None
else:
x = (b2 * c1 - b1 * c2) / determinant
y = (a1 * c2 - a2 * c1) / determinant
return np.array([x, y])
E = line_intersection(B, H, A, C)
fig, ax = plt.subplots(figsize=(8, 6))
ax.plot([A[0], B[0], C[0], A[0]], [A[1], B[1], C[1], A[1]], 'k-', label='Tam giác ABC')
ax.plot([B[0], M[0]], [B[1], M[1]], 'g--', label='BM')
ax.plot([A[0], M[0]], [A[1], M[1]], 'c--', label='AM')
ax.plot([B[0], H[0]], [B[1], H[1]], 'r-', label='BH ⊥ AM')
ax.plot([B[0], E[0]], [B[1], E[1]], 'r--', label='BH cắt AC tại E')
for point, name in zip([A, B, C, M, H, E], ['A', 'B', 'C', 'M', 'H', 'E']):
ax.plot(point[0], point[1], 'ko')
ax.text(point[0] + 0.2, point[1] + 0.2, name, fontsize=12)
ax.set_aspect('equal')
ax.set_title("Hình vẽ minh họa Câu 1")
ax.legend()
ax.grid(True)
plt.tight_layout()
plt.savefig("hinh_cau1.png") # Lưu ảnh
plt.show()
draw_cau1_image()
0
import matplotlib.pyplot as plt
import numpy as np
def draw_cau1_image():
A = np.array([0, 0])
B = np.array([0, 4])
C = np.array([6, 0])
AB = np.linalg.norm(B - A)
BC = C - B
BC_unit = BC / np.linalg.norm(BC)
M = B + AB * BC_unit
def foot_of_perpendicular(P, A, B):
AP = P - A
AB = B - A
proj_len = np.dot(AP, AB) / np.dot(AB, AB)
proj = A + proj_len * AB
return proj
H = foot_of_perpendicular(B, A, M)
def line_intersection(P1, P2, Q1, Q2):
A1, B1 = P1, P2
A2, B2 = Q1, Q2
a1 = B1[1] - A1[1]
b1 = A1[0] - B1[0]
c1 = a1 * A1[0] + b1 * A1[1]
a2 = B2[1] - A2[1]
b2 = A2[0] - B2[0]
c2 = a2 * A2[0] + b2 * A2[1]
determinant = a1 * b2 - a2 * b1
if determinant == 0:
return None
else:
x = (b2 * c1 - b1 * c2) / determinant
y = (a1 * c2 - a2 * c1) / determinant
return np.array([x, y])
E = line_intersection(B, H, A, C)
fig, ax = plt.subplots(figsize=(8, 6))
ax.plot([A[0], B[0], C[0], A[0]], [A[1], B[1], C[1], A[1]], 'k-', label='Tam giác ABC')
ax.plot([B[0], M[0]], [B[1], M[1]], 'g--', label='BM')
ax.plot([A[0], M[0]], [A[1], M[1]], 'c--', label='AM')
ax.plot([B[0], H[0]], [B[1], H[1]], 'r-', label='BH ⊥ AM')
ax.plot([B[0], E[0]], [B[1], E[1]], 'r--', label='BH cắt AC tại E')
for point, name in zip([A, B, C, M, H, E], ['A', 'B', 'C', 'M', 'H', 'E']):
ax.plot(point[0], point[1], 'ko')
ax.text(point[0] + 0.2, point[1] + 0.2, name, fontsize=12)
ax.set_aspect('equal')
ax.set_title("Hình vẽ minh họa Câu 1")
ax.legend()
ax.grid(True)
plt.tight_layout()
plt.savefig("hinh_cau1.png") # Lưu ảnh
plt.show()
draw_cau1_image()