Está en la página 1de 12

INTERPO.

DE STIRLING
program Stirling
real (4) x(-2:2),y(-2:2),xi,yi
write (*,*) 'Ingrese el valor de n'
write (*,*) 'n=1 o n=2'
read (*,*) n
write (*,*) 'Ingrese los valores de xi'
do j=-n,n
read (*,*) x(j)
end do
write (*,*) 'Ingrese los valores de yi'
do j=-n,n
read (*,*) y(j)
end do
write (*,*) 'Ingrese el valor a interpolar'
read (*,*) xi
h=x(1)-x(0)
u=(xi-x(0))/h
if (n.eq.1) then
yi=y(0)+u*0.5*(y(1)-y(-1))+0.5*u**2*(y(1)-2*y(0)+y(-1))
end if
if (n.eq.2) then
yi=y(0)+0.5*(y(1)-y(-1))*u+0.5*u**2*(y(1)-2*y(0)+y(-1))+(u**3-u)*(y(2)2*y(1)+2*y(-1)-y(-2))/12+(u**4-u**2)/24*(y(2)-4*y(1)+6*y(0)-4*y(-1)+y(2))
end if

write (*,*) yi
end program
INTERPOLACION POLINOMIO NGF
program interpolacionNGF
real (4) x(0:10),y(0:10),xi,yi,h,u,m,suma,fac1,fac2,it,fi,ft,fit
write (*,*) 'Ingrese el valor de m'
read (*,*) m
write (*,*) 'Ingrese los valores de xi'
do i=0,m
read(*,*) x(i)
end do
write (*,*) 'Ingrese los valores de yi'
do i=0,m
read(*,*) y(i)
end do
write (*,*) 'Ingrese el valor a interpolar'
read (*,*) xi
h=x(1)-x(0)
u=(xi-x(0))/h
suma=0
do i=1,m
fi=1
do j=1,i
fi=fi*j
end do

fac1=u
if (i.gt.1) then
do j=2,i
fac1=fac1*(u-j+1)
end do
end if
fac1=fac1/fi
fac2=0
do t=0,i
if (t.eq.0)

then

ft=1
else
ft=1
do j=1,t
ft=ft*j
end do
end if
fit=i-t
if (fit.eq.0) then
fit=1
else
fit=1
do j=1,(i-t)
fit=fit*j
end do

end if
it=fi/(ft*fit)
fac2=fac2+(-1)**(t)*it*y(i-t)
end do
suma=suma+fac1*fac2
end do
yi=y(0)+suma
write (*,*) yi
end program
POLINOMIO DE INTERP.NGB
!Formula de Interpolacion de Newton Gregory Backward (NGB)
program interNGB
real (4) x(-10:0),y(-10:0),xi,yi,h,u,m,suma,fac1,fac2,it,fi,ft,fit
write (*,*) 'Ingrese el valor de m'
read (*,*) m
write (*,*) 'Ingrese los valores de xi'
do i=-m,0
read(*,*) x(i)
end do
write (*,*) 'Ingrese los valores de yi'
do i=-m,0
read(*,*) y(i)
end do
write (*,*) 'Ingrese el valor a interpolar'
read (*,*) xi

h=x(0)-x(-1)
u=(xi-x(0))/h
suma=0
do i=1,m
fi=1
do j=1,i
fi=fi*j
end do
fac1=u
if (i.gt.1) then
do j=2,i
fac1=fac1*(u+j-1)
end do
end if
fac1=fac1/fi
fac2=0
do t=0,i
if (t.eq.0)

then

ft=1
else
ft=1
do j=1,t
ft=ft*j
end do
end if

fit=i-t
if (fit.eq.0) then
fit=1
else
fit=1
do j=1,(i-t)
fit=fit*j
end do
end if
it=fi/(ft*fit)
if (i.eq.1) then
fac2=y(0)-y(-1)
else
fac2=fac2+(-1)**(t)*it*y(t-i)
end if
end do
suma=suma+fac1*fac2
end do
yi=y(0)+suma
write (*,*) yi
end program
Adams bashforth 1ra derivada
!Soluciona EDO de la forma Y'=f(x,y)
program AB4
real (4) x(0:10),h,z(0:10),ni

write (*,*) 'SOLUCION a EDO de la forma dY/dx=f(x,y)'


write (*,*) 'ingrese los valores iniciales x0 e y0'
read (*,*) x(0),z(0)
write (*,*) 'ingrese pequea variacion h'
read (*,*) h
write (*,*) 'ingrese el numero de iteraciones'
read (*,*) ni
!aplicamos euler-cauchy
do n=0,2
z(n+1)=z(n)+h*f(x(n),z(n))
x(n+1)=x(n)+h
write (*,*) z(n+1),x(n+1)
end do
!aplicamos Adams-Bashforth
do n=3,ni-1
z(n+1)=z(n)+h/24*(55*f(x(n),z(n))-59*f(x(n-1),z(n-1))+37*f(x(n2),z(n-2))-9*f(x(n-3),z(n-3)))
x(n+1)=x(n)+h
write (*,*) z(n+1),x(n+1)
end do
write(*,*)'el resultado es ',' Y','=',z(ni)
write (*,*)'para ',' X','=',x(ni)
end program
function f(x,y)
f=3*x**2-4*x**4+4*y

return
PROBLEMA 1
PARTE A
!Soluciona EDO de la forma
!

y'=F(x,y(x))

program ADAMSBASHFORTH
real (4) x(0:10),y(0:10),z(0:10),h,Ni
write (*,*) 'ingrese las condiciones iniciales x(0) , y(0),z(0) '
read (*,*) x(0),y(0),z(0)
write (*,*) 'ingrese variacion de x '
read (*,*) h
write (*,*) 'ingrese el numero de iteraciones'
read (*,*) Ni
!Utilizando esquema de Euler
do N=0,2
z(N+1)=z(N)+h*F(x(N),y(N))
y(N+1)=y(n)+h*z(N)
x(N+1)=x(N)+h
write (*,*) z(N+1),y(N+1),x(N+1)
end do
!utilizando Adams - Bashfort
do N=3,Ni

z(N+1)=z(N)+h/24*(55*f(x(N),y(N))-59*f(x(N-1),y(N-1))+37*f(x(N-2),y(N2))-9*f(x(N-3),y(N-3)))
y(N+1)=y(N)+h/24*(55*z(N)-59*z(N-1)+37*z(N-2)-9*z(N-3))
x(N+1)=x(N)+h
write (*,*) z(N+1),y(N+1),x(N+1)
end do
write(*,*)'El resultado final es '
write(*,*) z(Ni+1),y(Ni+1),x(Ni+1)
end program
function f(x,y)
f=4*(2.7)**((0.8)*x) - (0.5)*y
return
end function
PROGRAM ADAMSMOULTON
real(4) z(0:10,0:10),x(0:10),h,i,Ni,Zf(15)
write (*,*) 'Ingrese los valores iniciales de X0 ,Y0'
read (*,*) x(0),z(0,0)
write (*,*) 'Ingrese TOLERANCIA'
read (*,*) TOL
write (*,*) 'Ingrese el numero de iteracciones'
read (*,*) Ni
write (*,*) 'ingrese la variacion de x'
read (*,*) h
WRITE(*,*)'INGRESE EL VALOR INICIAL fz0'
READ(*,*)Zf(0)

!UTILIZANDO EL ESQUEMA DE EULER


Zf(0)=z(0,0)
do N=1,2
Z(0,n)=Z(0,n-1)+h*F(x(n-1),z(0,n-1))
zf(N)=z(0,N)
x(N)=x(N-1)+h
write (*,*) z(0,N),x(N)
end do
do N =3,Ni
z(0,N)=ZF(N-1)
zf(N)=ZF(N-1)
x(N)=x(N-1)+h
i=0
20

i=i+1

z(i,n)=zf(n-1)+h/24*(9*f(x(n),zf(n))+19*f(x(n-1),zf(n-1))-5*f(x(n2),zf(n-2))+f(x(n-3),zf(n-3)))
zf(n)=z(i,n)
!calculo de la tolerancia
EE=abs(z(i,N)-z(i-1,N))!ERROR
if (EE.GT.TOL) then
goto 20
end if
write (*,*) zf(n),x(n)
end do
end

program

function f(x,y)
f=15*cos(x*y)+6*z**2
return
end function
program storme_verlet

real(4) x (100), b(100),Y(100) , V(100), tol, h


write(*,*) 'ingrese el valor inicial x0'
read(*,*) x0
write(*,*) 'ingrese el valor inicial y0'
read(*,*) y0
write(*,*) 'ingrese el valor inicial x1'
read(*,*) x1
write(*,*) 'ingrese el valor inicial y1'
read(*,*) y1
write(*,*) 'ingrese la tolerancia'
read(*,*) tol
!calculo
h=0.1
X(0)=X0
Y(0)=Y0
X(1)=X1
Y(1)=X1
do i= 1, 4

x(i+1)=x(i) + h
10 v(i)=(y(i)-y(i-1))/(2*h)
b(i)= 5*sin(x(i)*y(i))-3*v(i)**2
Y(i+1)=2*y(i)-y(i-1)+b(i)*(h**2)
if(abs(Y(i+1)-y(i)).LE.tol) then
y(i+1) = Y(i)
goto 10
end if
end do
write(*,*) x(i), y(i)
end