# 境界条件を適用 A = A.tocsr() for i inrange(Nx): row = i * Ny A[row, row] = 1 B[row] = u_top[i] A[row + Ny - 1, row + Ny - 1] = 1 B[row + Ny - 1] = u_bottom[i]
# 方程式を解く u = spsolve(A, B) u = u.reshape((Nx, Ny))
# 結果をプロット plt.figure(figsize=(8, 6)) plt.contourf(X, Y, u, cmap='viridis') plt.colorbar() plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Velocity Distribution of the Incompressible Stokes Equation') plt.show()
plt.figure(figsize=(10, 6)) plt.plot(solution.t, solution.y[0], label='Population of Species 1') plt.plot(solution.t, solution.y[1], label='Population of Species 2') plt.xlabel('Time') plt.ylabel('Population') plt.title('Simulation of Lotka-Volterra Equations') plt.grid(True) plt.legend() plt.show()
params, params_covariance = curve_fit(linear_func, time, distance) a, b = params
結果をグラフ化します。
1 2 3 4 5 6 7
plt.scatter(time, distance, label='Data') plt.plot(time, linear_func(time, a, b), label='Linear Fit') plt.xlabel('Time') plt.ylabel('Distance') plt.title('Linear Fit using Least Squares Method') plt.legend() plt.show()