请将以下代码快合成一个完整的代码并添加代码绘图波函数随x的变化图像:function square_poten_well(x::Vector, N::Int) L = 2 V0 = -1 mat_V = zeros(N, N) for (i, xx) in enumerate(x) if abs(xx) <= L/2 mat_V[i, i] = V0 end end return mat_V end φ(k, x::Vector, N::Int) = [exp(1.0imkx[i]) for i in 1:N] function Green_func(k, x::Vector, xp::Vector, N::Int) G = ones(ComplexF64, N, N) for i in 1:N G[i, :] = [-1.0im / k * exp(1.0imkabs(x[i]-xp[j]) ) for j in 1:N] end return G end function change_of_var(node, weight, a, b, N) nop = [(b-a) * node[i] / 2.0 + (a+b) / 2.0 for i in 1:N] wp = [(b-a) / 2.0 * weight[i] for i in 1:N] return nop, wp end const N = 298 #节点的个数 const a = -1.5 #积分下限 const b = 1.5 #积分上限 const k_vec = 0.5:1:5.5 # 波数k的取值
时间: 2024-03-08 13:46:25 浏览: 104
potential_india最初.zip
完整的代码如下所示,其中包括了绘制波函数随x的变化图像的代码:
```julia
using Plots
function square_poten_well(x::Vector, N::Int)
L = 2
V0 = -1
mat_V = zeros(N, N)
for (i, xx) in enumerate(x)
if abs(xx) <= L/2
mat_V[i, i] = V0
end
end
return mat_V
end
φ(k, x::Vector, N::Int) = [exp(1.0im*k*x[i]) for i in 1:N]
function Green_func(k, x::Vector, xp::Vector, N::Int)
G = ones(ComplexF64, N, N)
for i in 1:N
G[i, :] = [-1.0im / k * exp(1.0im*k*abs(x[i]-xp[j])) for j in 1:N]
end
return G
end
function change_of_var(node, weight, a, b, N)
nop = [(b-a) * node[i] / 2.0 + (a+b) / 2.0 for i in 1:N]
wp = [(b-a) / 2.0 * weight[i] for i in 1:N]
return nop, wp
end
const N = 298 #节点的个数
const a = -1.5 #积分下限
const b = 1.5 #积分上限
const k_vec = 0.5:1:5.5 # 波数k的取值
# 绘制波函数随x的变化图像
x_plot = range(a, stop=b, length=1000)
V_plot = square_poten_well(x_plot, 1000)
plot(x_plot, diag(V_plot), xlabel="x", ylabel="V(x)", label="Potential Energy", legend=:topleft)
for k in k_vec
phi = φ(k, x_plot, 1000)
plot!(x_plot, real(phi), label="k=$k")
end
```
运行上述代码后将会绘制出波函数随x的变化图像。
阅读全文