Méthode euler rk2,rk4

club-savoir -  
 sabri-1107 -
Bonjour,je suis entrain de résoudre l'eqd suivant:
dy/dx=(2/x)*y+x**2*exp(x) avec les condition : 1<=x<=2, y(1)=0
et voilà la solution exact : y(x)=t**2*(exp(x)-exp(1.))

alors mon problème c'est que j'ai pas arrivé à avoir les solution exact avec la programmation suivant :
donc pouvez vous m'aider a trouver l' error .et merci

program eqd
implicit none
real(kind=8)::h,yold,ynew,x
real(kind=8)::xi,xf
integer::i,n

print*,'donner h'
read*,h
print*,'donner xi,xf'
read*,xi,xf

n=(xf-xi)/h
yold=0.
x=1.
do i=1,n-1

call euler(h,yold,ynew,x)
call rk2(h,yold,ynew,x)
call rk4(h,yold,ynew,x)
print*,x,ynew,x*x*(exp(x)-exp(1.)),abs(ynew-x*x*(exp(x)-exp(1.)))

end do
end program
!-------------------------
subroutine euler (h,yold,ynew,x)
implicit none
real(kind=8),intent(in)::h
real(kind=8),intent(out)::yold,ynew,x
real(kind=8)::f

ynew=yold+h*f(yold,x)
yold=ynew

end subroutine
!-------------
real(kind=8) function f(y,x)
implicit none
real(kind=8)::y,x
f=(2./x)*y+x*x*exp(x)
end function
!--------------
subroutine rk2(h,yold,ynew,x)
implicit none
real(kind=8),intent(in)::h
real(kind=8),intent(out)::yold,ynew,x
real(kind=8)::f,k

k=h*f(yold,x)
ynew=yold+h*f(yold+k*0.5,x+h*0.5)
x=x+h
yold=ynew

end subroutine
!----------------
subroutine rk4(h,yold,ynew,x)
implicit none
real(kind=8),intent(in)::h
real(kind=8),intent(out)::yold,ynew,x
real(kind=8)::f,k1,k2,k3,k4

k1=h*f(yold,x)
k2=h*f(yold+k1*0.5,x+h*0.5)
k3=h*f(yold+k2*0.5,x+h*0.5)
k4=h*f(yold+k3,x+h)
ynew=yold+(k1+k2+k3+k4)
x=x+h
yold=ynew

end subroutine
Configuration: Windows XP
Firefox 2.0.0.14

1 réponse

  1. sabri-1107
     
    c'est le programme rk2 sou fortran

    c programme rk2
    parameter(n=11)
    dimensionx(n),y(n)
    donn‚e
    data xf,x1/2,0,1,0/
    dx=(xf+xi)/(n=1)
    c condition :initiale
    i=1
    x(1)=1,0
    y(1)=0,0
    print*,i=1,x(1),y(1)
    teration
    do 10 ni=1,n=1
    etape prediction
    ychap=y1+dx*f(xi,yi)
    etape correction
    x(i+1)=x1+dx
    y(i+1)=y(1)+0,5+dx*(f(xi,yi)+f(xi+1,ychap))
    print*,........
    print*,i,x(i+1),y(i+1)
    10 continue
    stop
    end
    c sous programe fonction f(a,b)
    =a*a+b*b+1
    return
    end
    1
    1. KAMAL
       
      MERCI SABRI POUR LA REPENSE, ÇA MA AIDE A TROUVER L ERREUR .j'aimerais bien de te correspondre sur ton MSN
      0
      1. sabri-1107 > KAMAL
         
        de rien mon amies mon émail est sabri-1107@hotmail.com
        0