- #1
fahad20
- 8
- 0
hello...i m trying to solve this ordinary differential equation problem..but it is giving errors..pleasezz help
problem: d^2 T/Dr^2 + (1/r) DT/Dr=1+ (r/R)^2
T'(0)=0 and T(R)=0
solve this problem for T(r),where R=1.0
SOLUTION I HAVE CUM UP WITH:
put R=1 in this equation...
now let v=T'
T''=V'
so
DT/Dr=v
Dv/dr=1+(T**2/V**2)-(V**2/T)
V(0)=0 and T(R)=0
and now here's the code...
dimension p(100,4),r(100),xn(100),xt(100)
write(*,10)
10 format(1x,'input number of equation:')
read(*,*)N
write(*,12)
12 format(1x,'enter the initial value of the independent variable:')
read(*,*)T
write(*,14)
14 format(1x,'enter the increment of the independent variable:')
read(*,*)dt
write(*,16)
16 format(1x,'enter the ending value of the independent variable:')
read(*,*)tend
write(*,18)
18 format(1x,'enter the initial value of the dependent variables:')
do 20 i=1,n
20 read(*,*)r(i)
write(*,22)
22 format(9x,'t',5x,'r(1) through r(n)')
write(*,24) T,(r(i),i=1,n)
24 format(f10.3,5e14.5)
26 call rkn(x,n,dt,t,p,xt,xn)
t=t+dt
do 30 i=1,n
30 r(i)=xn(i)
write(*,24)t,(r(i),i=1,n)
if (t.ge.tend) goto 50
goto 26
50 write(*,52)
52 format(1x,'r-k parameters are:')
do 54 i=1,n
54 write(*,56) (p(i,j),j=1,4)
56 format(4e15.5)
end
function f(r,t,i,n)
dimension r(n)
goto (10,20),i
10 f=r(1)
return
20 f=1+(r(2)**2/r(1)**2)-(r(1)**2/r(2))
return
end
subroutine rkn(xin,n,dt,t,p,xt,xout)
! solving n first-order ode d(xin)/dt=f(xin,t)
!knowing xin at t,this sub.finds xout at t+dt
!p are the runge-kutta 4th-order parameters
dimension p(n,4),xin(n),xout(n),xt(n)
do 5 i=1,n
5 p(i,1)=dt*f(xin,t,i,n)
do 15 j=2,3
do 10 i=1,n
10 xt(i)=xin(i)+p(i,j-1)/2.
do 15 i=1,n
15 p(i,j)=dt*f(xt,t+dt/2.,i,n)
do 20 i=1,n
20 xt(i)=xin(i)+p(i,3)
do 25 i=1,n
p(i,4)=dt*f(xt,t+dt,i,n)
25 xout(i)=xin(i)+(p(i,1)+2.*(p(i,2)+p(i,3))+p(i,4))/6.
return
end
but it is giving eror..please correct this..thank u
problem: d^2 T/Dr^2 + (1/r) DT/Dr=1+ (r/R)^2
T'(0)=0 and T(R)=0
solve this problem for T(r),where R=1.0
SOLUTION I HAVE CUM UP WITH:
put R=1 in this equation...
now let v=T'
T''=V'
so
DT/Dr=v
Dv/dr=1+(T**2/V**2)-(V**2/T)
V(0)=0 and T(R)=0
and now here's the code...
dimension p(100,4),r(100),xn(100),xt(100)
write(*,10)
10 format(1x,'input number of equation:')
read(*,*)N
write(*,12)
12 format(1x,'enter the initial value of the independent variable:')
read(*,*)T
write(*,14)
14 format(1x,'enter the increment of the independent variable:')
read(*,*)dt
write(*,16)
16 format(1x,'enter the ending value of the independent variable:')
read(*,*)tend
write(*,18)
18 format(1x,'enter the initial value of the dependent variables:')
do 20 i=1,n
20 read(*,*)r(i)
write(*,22)
22 format(9x,'t',5x,'r(1) through r(n)')
write(*,24) T,(r(i),i=1,n)
24 format(f10.3,5e14.5)
26 call rkn(x,n,dt,t,p,xt,xn)
t=t+dt
do 30 i=1,n
30 r(i)=xn(i)
write(*,24)t,(r(i),i=1,n)
if (t.ge.tend) goto 50
goto 26
50 write(*,52)
52 format(1x,'r-k parameters are:')
do 54 i=1,n
54 write(*,56) (p(i,j),j=1,4)
56 format(4e15.5)
end
function f(r,t,i,n)
dimension r(n)
goto (10,20),i
10 f=r(1)
return
20 f=1+(r(2)**2/r(1)**2)-(r(1)**2/r(2))
return
end
subroutine rkn(xin,n,dt,t,p,xt,xout)
! solving n first-order ode d(xin)/dt=f(xin,t)
!knowing xin at t,this sub.finds xout at t+dt
!p are the runge-kutta 4th-order parameters
dimension p(n,4),xin(n),xout(n),xt(n)
do 5 i=1,n
5 p(i,1)=dt*f(xin,t,i,n)
do 15 j=2,3
do 10 i=1,n
10 xt(i)=xin(i)+p(i,j-1)/2.
do 15 i=1,n
15 p(i,j)=dt*f(xt,t+dt/2.,i,n)
do 20 i=1,n
20 xt(i)=xin(i)+p(i,3)
do 25 i=1,n
p(i,4)=dt*f(xt,t+dt,i,n)
25 xout(i)=xin(i)+(p(i,1)+2.*(p(i,2)+p(i,3))+p(i,4))/6.
return
end
but it is giving eror..please correct this..thank u