You are on page 1of 3

Algoritmos en Fortran

Program algoritmo_de_biseccion

Integer Nmax,i
Real a, b, p, f, Tol

Write(*,*)"--------------Algoritmo de Biseccion------------"
Write(*,*)""
Write(*,*)"Digite el rango a,b"
Read (*,*)a,b

Do while (f(a)*f(b)>0)
Write(*,*)"Digite otro rango a,b"
Read (*,*)a,b
End do

Write(*,*)"Digite la tolerancia"
Read (*,*)Tol

Write(*,*)"Digite el numero maximo de iteraciones"


Read (*,*)Nmax
Write(*,*)"la funcion a analizar es:f=3x^2-2x-5"
i=1

Do while (i<Nmax)
p=(a+b)/2
if(abs(f(p))<Tol) Then
Write (*,*)" La raiz de la funcion es",p
pause
Stop
end if
If(f(a)*f(p)<0)Then
b=p
else
a=p
End If
i=i+1
End do
Write (*,*)" Se ha superado el maximo numero de iteraciones"
Pause
End program

Function f(x)
Real x,f
f=3*x**2-2*x-5
Return
End Function
Program algoritmo_del_punto_fijo

Integer Nmax,i
Real p, h, Tol , g ,Xo,E

Write(*,*)"--------------Algoritmo del metodo del punto fijo---------"


Write(*,*)""
Write(*,*)"Digite el valor inicial Xo"
Read (*,*)Xo

Write(*,*)"Digite la tolerancia"
Read (*,*)Tol

Write(*,*)"Digite el numero maximo de iteraciones"


Read (*,*)Nmax
Write(*,*)"la funcion a analizar es:f(x)=3x^2-2x-5"
Write(*,*)"Entoces g(x)=(2x+5)/(3x)"
Write(*,*)""

E=Tol+1
i=1

Do while (h(Xo)/=0.AND.E>Tol.AND.i<=Nmax)
p=g(Xo)
E=abs(p-Xo)
Xo=p
i=i+1
Write(*,*)"Xo=",Xo
End do
if(h(Xo)==0) Then
Write (*,*)"... La raiz de la funcion es:",Xo
pause
else
If(E<Tol)Then
Write (*,*)" Una aproximacion de la raiz :",Xo
pause
Else
Write (*,*)" Se supero el maximo numero de iteraciones"
Pause
End If
Pause
End if
End program

Function h(x)
Real x,h
h=3*x**2-2*x-5
Return
End Function

Function g(x)
Real x,g
g=(2*x+5)/(3*x)
Return
End Function
Program algoritmo_del_metodo_de_Newton_Raphson

Integer Nmax,i
Real p, f, Tol , g ,Xo ,X

Write(*,*)"-------------Algoritmo del metodo de Newton Raphson ------"


Write(*,*)""
Write(*,*)"Digite el valor inicial Xo"
Read (*,*)Xo
Write(*,*)"Digite la tolerancia"
Read (*,*)Tol
Write(*,*)"Digite el numero maximo de iteraciones"
Read (*,*)Nmax
Write(*,*)"la funcion a analizar es:f(x)=3x^2-2x-5"
Write(*,*)"Entoces g(x)=6x-2"
Write(*,*)""

i=1

Do while (i<=Nmax)
X=Xo-f(Xo)/g(Xo)
if(abs(X-Xo)<Tol) Then
Write (*,*)"... La raiz de la funcion es:",X
pause
Stop
End If
Xo=X
i=i+1
Write(*,*)"X=",X
End do
Write (*,*)" Se ha superado el maximo numero de iteraciones"
Pause
End program

Function f(x)
Real x,f
f=3*x**2-2*x-5
Return
End Function

Function g(x)
Real x,g
g=6*x-2
Return
End Function