FUNCTION3
!Program name: FUNCTION3
!Euler’s method for
differential equation dy/dx=-xy
!The exact solution:
y=exp(-x^2/2)
!y(n+1)= y(n)+h(-xy)
!Y(n+1) <=> X+h
real
:: x, y, h, exact, error
integer
:: i
func(x,y)=-x*y
h=0.01
y=1.
do
i=0,1
x=i
y=y+h*func(x,y)
exact=exp((-(x+h)**2)/2)
error=exact-y
print *, i, x+h, y, exact, error
end
do
stop
Comentários
Postar um comentário