Bohrium
robot
新建

空间站广场

论文
Notebooks
比赛
课程
Apps
我的主页
我的Notebooks
我的论文库
我的足迹

我的工作空间

任务
节点
文件
数据集
镜像
项目
数据库
公开
大作业2
python
python
bohrffb150
更新于 2024-07-07
推荐镜像 :FEALPy :2.0.1.1
推荐机型 :c2_m4_cpu
[2]
import numpy as np
import matplotlib.pyplot as plt

# 生成均匀网格
num_elements = 3
mesh = np.linspace(0, 1, num_elements + 1)

# 绘制网格
plt.figure(figsize=(8, 2))
plt.plot(mesh, np.zeros_like(mesh), marker='o', color='b', linestyle='-', linewidth=2)
plt.title('One-dimensional Uniform Mesh')
plt.xlabel('x')
plt.grid(True)
plt.show()

代码
文本
[3]
def compute_basis_gradients(xi, xi1, x):
""" Compute gradients of the basis functions on [xi, xi1] """
h = xi1 - xi
if x >= xi and x <= xi1:
if np.isclose(x, xi):
return 1 / h
elif np.isclose(x, xi1):
return -1 / h
else:
return np.array([1 / h, -1 / h])
else:
return 0

# 示例:在第一个单元 [0, 1/3] 上计算 x=0.1 处的梯度
xi = 0
xi1 = 1/3
x = 0.1
gradient = compute_basis_gradients(xi, xi1, x)
print(f'Gradient at x={x}: {gradient}')

Gradient at x=0.1: [ 3. -3.]
代码
文本
[4]
def compute_basis_gradients(xi, xi1, x):
""" Compute gradients of the basis functions on [xi, xi1] """
h = xi1 - xi
if x >= xi and x <= xi1:
if np.isclose(x, xi):
return 1 / h
elif np.isclose(x, xi1):
return -1 / h
else:
return np.array([1 / h, -1 / h])
else:
return 0

# 示例:在第一个单元 [0, 1/3] 上计算 x=0.1 处的梯度
xi = 0
xi1 = 1/3
x = 0.1
gradient = compute_basis_gradients(xi, xi1, x)
print(f'Gradient at x={x}: {gradient}')

Gradient at x=0.1: [ 3. -3.]
代码
文本
[5]
def assemble_local_stiffness_matrix(xi, xi1):
""" Assemble local stiffness matrix for a given element [xi, xi1] """
h = xi1 - xi
K_local = np.array([[1/h, -1/h],
[-1/h, 1/h]])
return K_local

# 示例:在第一个单元 [0, 1/3] 上组装局部刚度矩阵
xi = 0
xi1 = 1/3
K_local = assemble_local_stiffness_matrix(xi, xi1)
print('Local stiffness matrix:')
print(K_local)

Local stiffness matrix:
[[ 3. -3.]
 [-3.  3.]]
代码
文本
python
python
点个赞吧
推荐阅读
公开
第二题代码
python
python
cyc
更新于 2024-07-09
公开
4/19
python
python
Wonderwall
发布于 2024-04-24