首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用Julia求解热方程

用Julia求解热方程
EN

Stack Overflow用户
提问于 2022-05-26 14:20:42
回答 1查看 182关注 0票数 1

我是Julia的新用户,我想用它来解决PDE和ODE的数值问题。我试图运行的例子,可以在朱莉娅网站或GitHub,但我得到错误。例如,我想运行这个示例:

代码语言:javascript
复制
using OrdinaryDiffEq, ModelingToolkit, DiffEqOperators
# Method of Manufactured Solutions: exact solution
u_exact = (x,t) -> exp.(-t) * cos.(x)

# Parameters, variables, and derivatives
@parameters t x
@variables u(..)
Dt = Differential(t)
Dxx = Differential(x)^2

# 1D PDE and boundary conditions
eq  = Dt(u(t,x)) ~ Dxx(u(t,x))
bcs = [u(0,x) ~ cos(x),
        u(t,0) ~ exp(-t),
        u(t,1) ~ exp(-t) * cos(1)]

# Space and time domains
domains = [t ∈ IntervalDomain(0.0,1.0),
           x ∈ IntervalDomain(0.0,1.0)]

# PDE system
pdesys = PDESystem(eq,bcs,domains,[t,x],[u(t,x)])

# Method of lines discretization
dx = 0.1
order = 2
discretization = MOLFiniteDifference([x=>dx],t)

# Convert the PDE problem into an ODE problem
prob = discretize(pdesys,discretization)

# Solve ODE problem
using OrdinaryDiffEq
sol = solve(prob,Tsit5(),saveat=0.2)

# Plot results and compare with exact solution
x = (0:dx:1)[2:end-1]
t = sol.t

using Plots
plt = plot()

for i in 1:length(t)
    plot!(x,sol.u[i],label="Numerical, t=$(t[i])")
    scatter!(x, u_exact(x, t[i]),label="Exact, t=$(t[i])")
end
display(plt)
savefig("plot.png")

但我知道这个错误:

代码语言:javascript
复制
UndefKeywordError: keyword argument name not assigned

Stacktrace:
[1] PDESystem(eqs::Equation, bcs::Vector{Equation}, domain::Vector{Symbolics.VarDomainPairing}, ivs::Vector{Num}, dvs::Vector{Num}, ps::SciMLBase.NullParameters) (repeats 2 times)
@ ModelingToolkit C:\Users\rm18124.julia\packages\ModelingToolkit\57XKa\src\systems\pde\pdesystem.jl:75
[2] top-level scope
@ In[32]:22
[3] eval
@ .\boot.jl:373 [inlined]
[4] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base .\loading.jl:

1196

我检查了一遍PDESystem,看上去很好,有什么帮助吗?谢谢

EN

回答 1

Stack Overflow用户

发布于 2022-05-26 15:41:21

您忘记确保pdesys在docs中的名称,即@named pdesys = PDESystem(eq,bcs,domains,[t,x],[u(t,x)])

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72393344

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档