examen parcial de laboratorio de métodos numéricos de la física serrano
DESCRIPTION
Examen parcial xTRANSCRIPT
Examen parcial de laboratorio de métodos numéricos de la física
1) Método bisección
program biseccion
real(4) a,c,ea,es
write(*,*)'metodo de biseccion'
1 write(*,*)'ingrese a,c y es'
read(*,*)a,c,es
if(f(a)*f(c).le.0)then
goto 2
else
write(*,*)'no existe raiz entre a y c'
goto 1
end if
2 write(*,*)'resultados'
write(*,*)'n,a,c,b,ea,es'
n=0
n=n+1
3 b=(a+c)*0.5
if(f(a)*f(b).le.0)then
c=b
else
a=b
end if
ea=abs((b-bp)/b)*100
bp=b
write(*,4)n,a,c,b,ea,es
if(ea.le.es)then
write(*,*)'la raiz hallada es:',b,'con aproximacion al:',ea,'%'
else
goto 3
end if
4 format(i3,5(f8.4,1x))
end
function f(x)
f= x**2-2*x-8
return
end
Método de falsa posición
program falsa_posicion
real(4) a,c,ea,es,b,bp
write(*,*)'metodo de falsa_posicion'
1 write(*,*)'ingrese a,c y es'
read(*,*)a,c,es
if(f(a)*f(c).le.0)then
else
write(*,*)'no existe raiz entre a y c'
goto 1
end if
write(*,*)'resultados'
write(*,*)'a,f(a),b,f(b),c,f(c),ea'
n=0
2 n=n+1
b=a-((c-a)/(f(c)-f(a)))*f(a)
ea=abs((b-bp)/b)*100
write(*,3)a,f(a),b,f(b),c,f(c),ea
if(f(a)*f(b).le.0)then
c=b
else
a=b
end if
if(ea.le.es)then
write(*,*)'la raiz hallada es:',b,'con aproximacion al:',ea,'%'
else
bp=b
goto 2
end if
3 format(1x,7(f8.4,1x))
end
function f(x)
f=x**2-2*x-8
return
end
2) Método de newton raphson
program newton_raphson
real(4) x0,x1,tol,dfx,e
1 write(*,*)''
write(*,*)'metodo de newton_raphson'
write(*,*)'************************'
write(*,*)''
write(*,*)'ingreso de datos'
write(*,*)'****************'
write(*,*)'ingrese x0 y tol'
read(*,*)x0,tol
write(*,*)'resultados'
write(*,*)'n,x0,x1,e,tol'
h=0.01
n=0
2 n=n+1
dfx=(f(x0+h)-f(x0-h))/(2*h)
x1=x0-f(x0)/dfx
e=abs(f(x0)-f(x1))
if(e.gt.tol)then
write(*,4)n,x0,x1,e,tol
x0=x1
goto 2
else
write(*,4)n,x0,x1,e,tol
write(*,3)x1
end if
3 format('la raiz obtenida es:',f9.5)
4 format(1x,i2,4(f9.5,1x))
end
function f(x)
f=10*(exp(-x/2))*cos(3*x)
return
end
Método de la secante
program secante
real(4)x0,x1,tol,e
write(*,*)'metodo de la secante'
write(*,*)''
write(*,*)'ingre los puntos de aproximacion x0,x1 y tol'
read(*,*)x0,x1,tol
1 n=n+1
x2=x0-((x1-x0)/(f(x1)-f(x0)))*f(x0)
write(*,3)n,x2
e=abs(x2-x1)
if(e.le.tol)then
write(*,2)x2
else
x0=x1
x1=x2
goto 1
end if
2 format(1x,'valor final de la raiz=',f9.5)
3 format(1x,'valor aproximado de la raiz nro.',i2,'=',f9.5)
end
function f(x)
f=10*(exp(-x/2))*cos(3*x)
return
end