Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Facultad de ingeniería
Escuela de ingeniería civil cálculo numérico
MÉTODOS NUMÉRICOS
METODO DE LA BISECCION
Paso 1:
Elija valores iniciales inferior, x1, y superior, xu, que encierren la raíz, de forma tal que
la función cambie de signo en el intervalo. Esto se verifica comprobando que
f(x1)f(xu)<0.
Paso 2:
Una función aproximada de la raíz x1 se determina mediante:
x1 + xu
xr =
2
Paso 3:
Realice las siguientes evaluaciones para determinar en qué subintervalo esta la raíz:
a) si f(x1)f(xr)<0, entonces la raíz se encuentra dentro del subintervalo inferior o
izquierdo. Por lo tanto, haga xu=xr y vuelva al paso 2.
b) Si f(x1)f(xu)>0, entonces la raíz se encuentra dentro del subintervalo superior o
derecho. Por lo tanto, haga x1=xr y vuelva al paso 2.
c) Si f(x1)f(xu)=0, la raíz es igual a xr; termina el calculo.
El método de la Bisección, conocido también como de corte binario, de partición de
intervalos o de Bolzano, es un tipo de búsqueda incremental en el que el intervalo se
divide siempre a la mitad. Si la función cambia de signo sobre un intervalo, se evalúa el
valor de la función en el punto medio. La posición de la raíz se determina situándola en
punto medio del subintervalo, dentro del cual ocurre un cambio de signo.
DIAGRAMA DE FLUJO
INICIO
LEER
f(x) , a , b , E
V F
f(a)*f(b)<0
│b - a│ < F
E
V
x1 = (a + b) /
2
ESCRIBIR
V F “No exixte
f(a)*f(x1)<
0
a = x1
b = x1
f(x1)= F
0
V
a=b
ESCRIBIR
“La raíces:” x1
FIN
x k +1 = g ( x k )...........k =0,1,2,3,..............., n
x1 = g ( x 0 )
x 2 = g ( x1 )
x3 = g ( x3 )
…………
x n = g ( x n −1 )
Observación:
Teorema:
DIAGRAMA DE FLUJO
INICIO
LEER
g , x0 , E , N
k=1
x1 = g(x0)
│x1 – x0│ ≥ F
E
V
x0 = x1
g(x0) = g(x1)
k≠k+1
ESCRIBIR
x1 , k
FIN
g=inline(get(handles.edit2,'string'));
ezplot(g),grid on
close(metodopuntofijo)
METODO NEWTON-RAPHSON
Tal vez, de las formulas para localizar raíces, la formula de Newton-Raphson sea la más
ampliamente utilizada. Si el valor inicial para la raíz es xi, entonces se puede trazar una
tangente desde el punto [xi,f(xi)] de la curva. Por lo común, el punto donde esta tangente
cruza al eje x representa una aproximación mejorada de la raíz.
El método de Newton Raphson se deduce a partir de esta interpretación geométrica (un
método alternativo basado en la serie de Taylor. Se tiene que la primera derivada en x es
equivalente a la pendiente:
f ( xi ) − 0
f ' ( xi ) =
xi − xi +1
f ( xi )
xi +1 = xi − (1)
f ' ( xi )
INICIO
LEER
f , fd , x0 , E ,
k=1
x1 = x0 -
V
x0 = x1
x1 = x0 -
k = k +1
ESCRIBIR
x1 , k
FIN
f=inline(get(handles.edit1,'string'));
fd=inline(get(handles.edit2,'string'));
Xo=str2double(get(handles.edit3,'string'));
E=str2double(get(handles.edit4,'string'));
X1=Xo-f(Xo)/fd(Xo);
while abs(X1-Xo)>E
Xo=X1;
X1=Xo-f(Xo)/fd(Xo);
end
set(handles.edit5,'string',X1)
f=inline(get(handles.edit1,'string'));
ezplot(f),grid on
close(metodonewtonraphson)
METODO DE LA SECANTE
f ( x 0 ) − f ( x1 ) f ( x1 )
=
x 0 − x1 x1 − x 2
( x1 − x0 ) * f ( x1 )
x 2 = x1 −
f ( x1 ) − f ( x0 )
( xi − xi −1 ) * f ( xi )
En general: xi +1 = xi −
f ( xi ) − f ( xi −1 )
DIAGRAMA DE FLUJO
INICIO
LEER:
X0,X1,E
|x2-x1|>E
X0=X1
X1=X2
ESCRIBIR:
X2
FIN
f=inline(get(handles.edit1,'string'));
ezplot(f),grid on
close(metodosecante)
f ( x1 ) = a ( x1 − x 2 ) 2 + b( x1 − x 2 ) + c (3)
f ( x 2 ) = a( x 2 − x 2 ) 2 + b( x 2 − x 2 ) + c (4)
Observe que se ha limitado el subíndice “2” de la función por brevedad. Debido a que
se tienen tres ecuaciones, es posible encontrar los tres coeficientes desconocidos a, b y
c. Debido a que los términos de la ecuación (4) son cero, se encuentra inmediatamente
que c=f(x2). Así, el coeficiente c es igual al valor de la función evaluada en el tercer
valor inicial, x2. Este resultado se sustituye en las ecuaciones (2) y (3) para tener dos
ecuaciones con dos incógnitas:
f ( x 0 ) − f ( x 2 ) = a ( x 0 − x 2 ) 2 + b( x 0 − x 2 ) (5)
f ( x1 ) − f ( x 2 ) = a( x1 − x 2 ) 2 + b( x1 − x 2 ) (6)
Una manipulación algebraica permite encontrar los coeficientes restantes a y b. la
manera de hacer esto consiste en definir las diferencias:
h0 = x1 − x0
h1 = x 2 − x1
f ( x1 ) − f ( x0 )
δ0 =
x1 − x0
f ( x 2 ) − f ( x1 )
δ1 = (7)
x 2 − x1
b = ah1 + δ1
= f ( x2 )
cINICIO
Para encontrar la raíz se aplica la formula cuadrática a la ecuación (1). Sin embargo,
LEER
debido al error de redondeo potencial,
x0 , x1 , en
x2 , lugar
f(x) , E de usar la formula convencional, se
usará la formula alternativa, es decir:
dx1 = 1
− 2c
x3 − x 2 = (&)
x1 =b02 − 4ac
b±
O despejando la incógnita x3
│dx │ > E *− 2c F
x3 = x 2 1+
x1 b ± b 2 − 4ac
V
Obsérvese que al usar la formula cuadrática, es posible localizar tanto las raíces reales
h0 = x1 – x0
como las complejas. Esta es la mayor ventaja del método.
h1 = x2 – x1
Además, la ecuación (&) proporciona una forma directa para determinar el error de
d0 = (f(x1) – f(x0) / h0
aproximación. Debido a que el lado izquierdo representa la diferencia entre la raíz
d1 = (f(x2) – f(x1) / h1
estimada actual (x3) y la raíz estimada anterior (x2), el error se calcula como
a = (d1 – d0) / (h1 + h0)
x − x2
b= =1 +3d1
E ah 100%
x3
c = f(x1)
rad =
V │b+rad│>│b- F
rad│
dm = b + rad dm = b - rad
O
dxr = -2c / dm
xr = x2 + dxr
x0 = x1
DIAGRAMA DE FLUJO x1 = x2
x2 = xr
FIN
Universidad nacional jorge basadre grohmann
Facultad de ingeniería
Escuela de ingeniería civil cálculo numérico
f=inline(get(handles.edit4,'string'));
ezplot(f),grid on
close(metodomuller)
n x − xj
Li ( x) = ∏
x − xj
j= 0 i
j≠ i
( x − x1 )( x − x 2 ) ( x − x 0 )( x − x 2 ) ( x − x 0 )( x − x1 )
f 2 ( x) = f ( x0 ) + f ( x1 ) + f ( x2 )
( x 0 − x1 )( x 0 − x 2 ) ( x1 − x 0 )( x1 − x 2 ) ( x 2 − x 0 )( x 2 − x1 )
DIAGRAMA DE FLUJO
INICIO
n, xi ,v, f(x)
S=0
k=1, n,1
Num = 1
Den = 1
i=1, n,1
i≠
k
Den = Den*(xk-xi)
L=Num/Dem
S=S+L*f(xk)
ESCRIBIR
S
FIN
close(metodolagrange)
nn n
x∑ ∑ x ∑ xy
2
i i ii
a
i = 1 i= 1 i = 1
*n = n
b
nx∑ i ∑ yi
i= 1 i= 1
n n n n
∑ xy ∑ x
i= 1
ii
i= 1
i ∑ x ∑ xy
i= 1
2
i
i= 1
ii
n n n
∑ yi n
i= 1
INICIO
∑x ∑y
i= 1
i
i= 1
i
a= n n
LEER
m , xi , yi b= n n
∑ i ∑ xi
x 2
i= 1 i= 1
A11 = 0
A12 = 0
∑ i ∑ xi
x 2
i= 1 i= 1
n A22 = m n
∑x n
i= 1
i
B1 = 0
B2 = 0
∑x n
i= 1
i
i=1 , m , 1
DIAGRAMA DE FLUJO
A11 = A11 + xi2
A12 = A12+xi
A21 = A12
B1 = B1+xiyi
B2 = B2+yi
a=
a=
ESCRIBIR
Docente lic. Javier lozano a,b
- 22 -
FIN
Universidad nacional jorge basadre grohmann
Facultad de ingeniería
Escuela de ingeniería civil cálculo numérico
global A B x y
m=str2num(get(handles.edit1,'string'));
x=str2num(get(handles.edit2,'string'));
y=str2num(get(handles.edit3,'string'));
a11=0;
a12=0;
a22=m;
b1=0;
b2=0;
for i=1:m
a11=a11+(x(i))^2;
a12=a12+x(i);
a21=a12;
b1=b1+x(i)*y(i);
b2=b2+y(i);
end
A=(b1*a22-b2*a12)/(a11*a22-a12*a21);
B=(b2*a11-b1*a21)/(a11*a22-a12*a21);
davo=sprintf('y=%6.4fx+ %6.4f',A,B);
set(handles.edit4,'string',davo);
global A B x y
xx=min(x)-1:0.1:max(x)+1
yy=A*xx+B;
plot(x,y,'og',xx,yy),grid on;
Close(metodoregresionlineal)
METODO DE GAUSS-JORDAN
. . . . . . . . . . . . . . . . . . .
a a a . . . . . . . . a x b
n1 n2 n3 n n n
O también Ax+B, donde A es la matriz de coeficientes, x es el vector de la incógnita y
B es el vector de los termino independientes.
Procedimiento
1. Crear la matriz formada por la matriz de coeficientes y el vector de terminos
independientes.
2. mediante tranformadas elementales la matriz de coeficientes debe convertirse en
la matriz identidad, y los valores que esten en la posición del vector de terminos
independientes será el vector solucion.
3. entonces las raices del sistema son:
n3 n n3 n
Este proceso requiere de + n 2 − multiplicaciones y − sumas.
2 2 2 2
DIAGRAMA DE FLUJO
INICIO
LEER
n , aij
i=1,n,1
divisor aii
j = i , n+1 , 1
k=1,n,1
V F
i≠j
pivote = aki
j = i , n+1 ,
1
ESCRIBIR
Docente lic. Javier lozano ai , n
- 26 -
FIN
Universidad nacional jorge basadre grohmann
Facultad de ingeniería
Escuela de ingeniería civil cálculo numérico
close(metodogaussjordan)
METODO DE GAUSS-SEIDEL
b2 − a 21 x1 − a 23 x3
x2 = (&&)
a 22
b3 − a31 x1 − a32 x 2
x3 = (&&&)
a33
Ahora si empezamos el proceso de solución al escoger valores iniciales para las x. Una
forma simple para obtener los valores iniciales es suponer que todos son cero. Estos
k = 1 , max ite ,
1
DIAGRAMA DE FLUJO
i=1,n,1
xi = vi
i=1,n,1
S=0
j=1,n,1
V F
i≠j
S = S + a ij * xj
Vi = (bi – S) / 1000
xi = Vi
ESCRIBIR
Docente lic. Javier lozano Vi , i = 1, 2, 3…
- 29 -
FIN
Universidad nacional jorge basadre grohmann
Facultad de ingeniería
Escuela de ingeniería civil cálculo numérico
INTEGRACION NUMERICA
b b
I = ∫ f ( x)dx ≅ ∫ f 1 ( x)dx
a a
f (b) − f (a )
f1 ( x) = f (a) + ( x − a ) (*)
b −a
El área bajo esta línea recta res una aproximación de la integral de f(x) entre los límites
a y b.
b
f (b) − f (a )
I = ∫ f (a) + ( x − a ) dx
a
b −a
f (b ) − f ( a ) bf (a ) − af ( a ) − af (b) + af (a )
f1 ( x) = x+
b −a b −a
O
f (b) − f ( a ) bf ( a ) − af (b)
f1 ( x) = x+
b −a b −a
la cual se puede integrarse entre x = a y x = b para obtener:
f (b) − f (a ) x 2 bf (a ) − af (b) b
I = + x |a
b −a 2 b −a
Este resultado se evalúa para dar:
f (b) − f (a) (b 2 − a 2 ) bf ( a) − af (b)
I= + (b − a)
b −a 2 b −a
Ahora, como b 2 − a 2 = ( b − a )( b + a ),
INICIO
b +a
I = [ f (b) − f ( a )] + bf (a ) − af (b)
2
LEER
Multiplicando y agrupando términos
a , bse tiene:n
, f(x),
f ( a ) + f (b)
I = (b − a ) que es la formula del trapecio.
2
h=(b-a)/n
xI=a+i*h
S=f(a)+f(b)
i=1, n-1,1
xi=a+i*h
S=S+2*f(xi)
A=S*h/2
ESCRIBIR
Docente lic. Javier lozano A
- 32 -
FIN
Universidad nacional jorge basadre grohmann
Facultad de ingeniería
Escuela de ingeniería civil cálculo numérico
close(metododeltrapecio)
REGLA DE SIMPSON
Además de aplicar la regla del trapecio con una segmentación mas fina, otra forma de
obtener una estimación más exacta de una integral consiste en usar polinomios de grado
superior para unir los puntos.
i=0, n,1
xi=a+i*b
Si n par
i=2,n, 2
S=S+f(x1-2)+ 4f(xi-1)+f(xi)
I=h*S/3
ESCRIBIR
I
Docente lic. Javier lozano
- 35 -
FIN
Universidad nacional jorge basadre grohmann
Facultad de ingeniería
Escuela de ingeniería civil cálculo numérico
f=inline(get(handles.edit1,'string'));
a=str2double(get(handles.edit2,'string'));
b=str2double(get(handles.edit3,'string'));
n=str2double(get(handles.edit4,'string'));
h=(b-a)/n;
s=f(a)+f(b);
for i=1:n+1
x(i)=a+((i-1)*h);
y(i)=f(x(i));
end
x=[x,b,a,a];
y=[y,0,0,f(a)];
fill(x,y,[0.8 0.4 0.9])
for i=1:n+1
close(metodosimpsontres)
para obtener
3h
I ≅ [ f ( x0 ) + 3 f ( x1 ) + 3 f ( x 2 ) + f ( x3 )]
8
Donde h = (b-a)/3. Esta ecuación se llama regla de Simpson 3/8 debido a que h se
multiplica por 3/8. Esta es la tercera formula de integración cerrada de Newton-Cotes.
INICIO
Leer
f(x),a,b,n
DIAGRAMA DE FLUJO
h=(b-a)/n
i=0, n, 1
xi=a+i*h
Si n
multipl
o de 3
S=0
i=3,n,3
S=S+f(xi-3)+f(xi-2)+3f(xi-1)+f(xi)
I=3h*S/8
ESCCRIBIR
Docente lic. Javier lozano I
- 38 -
FIN
Universidad nacional jorge basadre grohmann
Facultad de ingeniería
Escuela de ingeniería civil cálculo numérico
f=inline(get(handles.edit1,'string'))
a=str2double(get(handles.edit2,'string'))
b=str2double(get(handles.edit3,'string'))
n=str2double(get(handles.edit4,'string'))
h=(b-a)/n
s=f(a)+f(b)
for i=1:n+1
x(i)=a+((i-1)*h)
y(i)=f(x(i))
end
x=[x,b,a,a]
y=[y,0,0,f(a)]
fill(x,y,[0.6 0.8 0.4])
close(metodosimpson8)
INTEGRALES MULTIPLES
∫∫ f ( x, y )dA
R
;donde R es una región
b −a g 2 ( x ) − g1 ( x)
h1 = h 2 ( x) =
2 2
h2 ( x 0 )
b
∫∫
g2 ( x)
f ( x, y ) dydx ≅
h1
[ f ( x0 , g1 ( x0 )) + 4 f ( x0, g1 ( x0 ) + h2 ( x)) + f ( x0 , g 2 ( x0 ))] +
a g1 ( x ) 3 3
h (x )
+ 4 2 1 [ f ( x1 , g1 ( x1 ) + 4 f ( x1 , g ( x1 ) + h2 ( x1 )) + f ( x1 , g 2 ( x1 ))] +
3
h (x )
+ 2 2 [ f ( x 2 , g1 ( x 2 )) + 4 f ( x 2 , g 1 ( x 2 ) + h2 ( x 2 )) + f ( x 2 , g 2 ( x 2 ))]
3
INICIO
Leer
DIAGRAMA DE FLUJO f(x,y), a, b, m, n, g1(x), g2(x)
h1=(b-a)/n
i=0, n, 1
xi=a+i*h1
h1=(g2(xi)-g1(xi))/m
j=o, m, 1
yi=g1(xi)+j*h2
S1=0
j=2, m, 2
S1=S1+f(xi, yj-2)+4f(xi,yj-1)+f(xi,yi)
Mi=S1*h2/3
S2=0
i=2, n, 2
S2=S2+Mi-2 +4Mi-1+Mi
Area=h1*S2/3
ESCRIBI
R
Docente lic. Javier lozano
Area
- 42 -
FIN
Universidad nacional jorge basadre grohmann
Facultad de ingeniería
Escuela de ingeniería civil cálculo numérico
METODO DE EULER
Figura 1
Y se obtiene:
y i +1 = yi + f ( xi , y i ) * h
DIAGRAMA DE FLUJO
INICIO
LEER
f(x,y) , a , b , n , y0
x0 = a
h = (b – 1) / n
i=1,n,1
y1 = y0 + h * f(x0,y0)
y0 = y1
x1 = x0 + h
x0 = x1
ESCRIBIR
y0
FIN
close(metodoeuler)
METODO DE RUNGE-KUTTA
x1 , y ( x1 ) =y1
x 2 , y ( x 2 ) =y 2
x 3 , y ( x 3 ) =y 3
......................
x n , y ( x n ) =y n
Se quiere calcular:
donde :
x − x1
h= 2
2
para la ecuación (1) tomamos el int ervalo [ x n , x n +1 ]
la ecuación(1) se puede escribir como :
h h
y ( x n +1 ) − y ( x n ) = [ y ' ( x n ) + 4 y ' ( x n + ) + y ' ( x n +1) ]
6 2
h ' h
y n +1 = y n + [ y ( x n ) + 4 y ' ( x n + ) + y ' ( x n +1 )]
6 2
h h h
Al el termino 4 y ' ( x n + ) se divide en los términos 2 y ' ( x n + ) + 2 y ' ( x n + ) para
2 2 2
h h
aproximar la pendiente de y ' ( x n + )INICIO
en el punto medio x n + de 2 maneras
2 2
distintas.
h h LEER h
y n +1 = y n + [ y ' ( x n ) + 2 y ' ( x n + + 2 y ' ( x n + ) + y ' ( x n +1 )]..............................2)
6 F(x,y),
2 a, b, n, y20
en la ecuación 2 se sustituyen las pendientes :
* K 1 = y ' ( x n ), donde y ' ( x n ) = f ( x n , y n ) ⇒K 1 = f ( x n , y n )
h=
h h h h
* K 2 = y ( x n + ), donde
'
y ( xn ) = f ( x n + ) ⇒ K 2 = f ( x n + , y n + * K1 )
'
2 2 2 2
x0 = a
h h h h
* K 3 = y ' ( x n + ), donde y ' ( xn ) = f ( xn + ) ⇒ K 2 = f ( xn + , y n + * K 2 )
2 2 2 2
i=1,n,1
* K 4 = y ( x n +1 ), donde
'
y ( x n ) = f ( x n +1 ) ⇒ K 4 = f ( x n +1 , y n + h * K 3 )
'
h
∴ y n +1k ==yf(x
n + ,y ()K 1 + 2 K 2 + 2 K 3 + K 4 )
1 0 60
k2 = f(x0+, y0+ ()(k1))
DIAGRAMA DE FLUJO k3 = f(x0+, y0+ ()(k2)
k4 = f(x0+h), y0 + hk3)
y1 = y0 + (k1+2k2+2k3+k4)
x1 = x0 + h
x0 = x1
y0 = y1
O
ESCRIBIR
Docente lic. Javier lozano y1
- 48 -
FIN
Universidad nacional jorge basadre grohmann
Facultad de ingeniería
Escuela de ingeniería civil cálculo numérico
f1=get(handles.edit1,'string');
f=inline(f1,'x','y');
ezmesh(f);grid on
close(metodorungekutta4)
DIAGRAMA DE FLUJO
f1=get(handles.edit1,'string');
f2=get(handles.edit2,'string');
f=inline(f1,'x','y1','y2');
g=inline(f2,'x','y1','y2');
a=str2double(get(handles.edit3,'string'));
b=str2double(get(handles.edit4,'string'));
y1=str2double(get(handles.edit5,'string'));
y2=str2double(get(handles.edit6,'string'));
y( x f ) =?
Entonces:
u1' = y ' = u 2
u 2' = y '' = u 3
.............................
u n' = y n = f ( x, u1 , u 2 , u 3 ,..........., u n )