! PROGRAM RK method to solve di/dt+iR/L=V/L
real::t,i,k1,k2,k3,k4,V,L,R,io
integer::j,jj,n
f(t,i)=V/L-R/L*i
V=20; L=0.4; R=2
open(1,file="RK_method.out")
open(2,file="RK_analytical.out")
t=0;i=0;h=0.4;n=20
write(1,*)t,i
do j=1,n
k1=h*f(t,i)
k2=h*f(t+0.5*h,i+0.5*k1)
k3=h*f(t+0.5*h,i+0.5*k2)
k4=h*f(t+h,i+k3)
i=i+k1/6+k2/3+k3/3+k4/6
t=t+h
write(1,*)t,i
enddo
io=V/R
t=0
do jj=1,n
i=io*(1-exp(-R/L*t))
write(2,*)t,i
t=t+h
enddo
end
real::t,i,k1,k2,k3,k4,V,L,R,io
integer::j,jj,n
f(t,i)=V/L-R/L*i
V=20; L=0.4; R=2
open(1,file="RK_method.out")
open(2,file="RK_analytical.out")
t=0;i=0;h=0.4;n=20
write(1,*)t,i
do j=1,n
k1=h*f(t,i)
k2=h*f(t+0.5*h,i+0.5*k1)
k3=h*f(t+0.5*h,i+0.5*k2)
k4=h*f(t+h,i+k3)
i=i+k1/6+k2/3+k3/3+k4/6
t=t+h
write(1,*)t,i
enddo
io=V/R
t=0
do jj=1,n
i=io*(1-exp(-R/L*t))
write(2,*)t,i
t=t+h
enddo
end
Comments
Post a Comment