Вы находитесь на странице: 1из 6

!

El metodo de biseccion es un metodo para resolver problemas munericos


!es el primer metodo visto en clases

!Datos de entrada
program M_B
implicit none
real:: a,b,tol,p,q,n,f,FA,FP
integer::i
!Ingreso de datos
!write(*,*)'ingresa los intervalo de a,b'
!write(*,*) 'separados por coma'
!read(*,*) a,b
a=1
b=3
print*,''
!write(*,*) 'ingreso de la tolerancia tol'
!read(*,*) tol
tol=0.0001
print*,''
!write(*,*) 'Ingreso de numero de iteraciones n= 100'
!read(*,*) n
!
n=100
!
!
if (f(a)*f(b)<0) then
do i=1,n
p=(a+b)/2.0
if(abs(f(p))<tol) then
write(*,*) 'La raiz es ',p
print*,''
else
if( (f(a)*f(p))< 0) then
b=p
else
a=p
end if
end if
end do
else
write(*,*) 'Error'
end if

pause
end program M_B
!
!
!
real function f(x)
Implicit none
real::x
f= x**2+4
end function

program punto_fijo
IMPLICIT NONE
real:: tol,p,P0,a,b,g
integer:: n,i
a=1
b=1
p0=1
tol=0.01
n=100
print*,''
!
!
!
if (g(a)*g(b)>0) then
do i=1,n
p=g(P0)
if (abs(p-P0)<tol) then
write(*,*)'la raiz es:',p
write(*,*)
else
P0=p
end if
end do
else
write(*,*) 'Error'
end if
stop
end program punto_fijo
real function g(x)
IMPLICIT NONE
real:: x
g=(3*x**2+3)**0.25
end function

program newton
IMPLICIT NONE
real:: tol,p,P0,f,g
integer:: n,i
P0=1
tol=0.00000000001
n=100
print*,''
!
!
do i=1,n
p=P0-(g(P0)/f(P0))
if (abs(p-P0)<tol) then
write(*,*)'la raiz es:',p
write(*,*)
else
P0=p
end if
end do
pause
end program newton
real function g(x)
IMPLICIT NONE
real:: x
g=x**2-6
end function
!derivada de la funcion g(x)
real function f(x)
IMPLICIT NONE
real:: x
f=2*x
end function

program secante
IMPLICIT NONE
real:: tol,p,P0,P1,g,q1,q0
integer:: n,i
P0=3
P1=2
tol=0.01
n=100
print*,''
!
!
do i=1,n
q0=g(P0)
q1=g(P1)
p=P1-((q1*(P1-P0))/(q1-q0))
if (abs(p-P1)<tol) then
write(*,*)'la raiz es:',p
write(*,*)
else
P0=P1
q0=q1
P1=p
q1=g(p)
end if
end do
pause
end program secante
real function g(x)
IMPLICIT NONE
real:: x
g=x**2-6
end function

program posicion_falsa
IMPLICIT NONE
real:: tol,p,P0,P1,g,q1,q0,q
integer:: n,i
P0=3
P1=2
tol=0.01
n=100
print*,''
!
!
do i=1,n
q0=g(P0)
q1=g(P1)
p=P1-((q1*(P1-P0))/(q1-q0))
if (abs(p-P1)<tol) then
write(*,*)'la raiz es:',p
write(*,*)
else
q=g(p)
if ((q*q1)<0) then
P0=P1
q0=q1
else
P1=p
q1=q
end if
end if
end do
pause
end program posicion_falsa
real function g(x)
IMPLICIT NONE
real:: x
g=x**2-6
end function

Вам также может понравиться