📄 laxwendroff.f90
字号:
module define
implicit none
integer,parameter::Nmax=200
real::dx,dt
contains
subroutine initial(u,x)
implicit none
real::u(0:Nmax),x(0:Nmax)
integer::j
do j=0,Nmax
if(x(j)<=0.2) then
u(j)=0.0
else if(x(j)>0.2.and.x(j)<=0.5) then
u(j)=sin((x(j)-0.2)*10*3.1415926)
else if(x(j)>0.5.and.x(j)<=0.7) then
u(j)=7.5*(x(j)-0.5)
else
u(j)=-1.0
end if
end do
end subroutine
end module
program main
use define
implicit none
real::x(0:Nmax),u(0:Nmax),u_1(0:Nmax)
real::lampta,a,T
integer::j,n,Step
T=1.0
dx=1.0/Nmax
a=0.2
lampta=0.1
dt=lampta*dx/a
Step=int(T/dt)
do j=0,Nmax
x(j)=0+dx*j
end do
call initial(u,x)
do n=1,Step
do j=1,Nmax-1
u_1(j)=u(j)-lampta*(u(j+1)-u(j-1))/2.0+lampta**2*(u(j+1)-2*u(j)+u(j-1))/2.0
end do
u_1(Nmax)=u_1(Nmax-1)
u_1(0)=0.0
u=u_1
print*,n
end do
open(2006,file="u.txt")
do j=0,Nmax
write(2006,*)u(j)
end do
open(2007,file="x.txt")
do j=0,Nmax
write(2007,*)x(j)
end do
end program
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -