Clase 1 3 Algoritmo Esp

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Taller de Análisis Numérico

Algorithms and convergence

Heetae Kim

Ingeniería Civil Industrial


Universidad de Talca

Heetae Kim, Ingeniería Civil Industrial Taller de Análisis Numérico


Algoritmos

Son los procesos de aproximación:

• Un algoritmo corresponde a un grupo de pasos ambiguos que desde una


entrada (input) de datos produce una respuesta en un tiempo finito.

• Los algoritmos computacionales son implementados a través de software


que pueden resolver problemas matemáticos, arrojando resultados
numéricos aproximados.

• A pesar de ser aproximados, los resultados obtenidos pueden tener un alto


(y creciente) grado de precisión.

Heetae Kim, Ingeniería Civil Industrial Taller de Análisis Numérico


Seudocódigo

• Metodología simple para describir un algoritmo de forma explicita.

• Uso del lenguaje natural.

• Lo usaremos para describir los métodos del ramo.

• Esto incluye:
‣ Entrada (Input)
‣ Salida (Output)
‣ Pasos (Steps)
‣ Condiciones (Conditions)

∑x i
= x1 + x2 +!+ x N
i=1

Heetae Kim, Ingeniería Civil Industrial Taller de Análisis Numérico


Ejemplo

• Un algoritmo para calcular


N

∑x i = x1 + x2 +!+ x N
i=1
cuando n y los números x1, x2, …, xn son dados, se puede escribir de la
siguiente maneras:

INPUT N, x1, x2, …, xn .


N
OUTPUT SUMA=
xi
xi .

STEP 1 Set SUMA = 0. (Initialize accumulator)


STEP 2 For i = 1, 2, …, N (loop)
Set SUMA = SUMA + xi. (Add the next term.)
STEP 3 OUTPUT (SUMA);
STOP.

Heetae Kim, Ingeniería Civil Industrial Taller de Análisis Numérico


Convenciones

• Un punto (.) indica el fin de un paso


• Un punto y coma (;) separa tareas dentro de un paso
• Las variables y elementos conocidos pueden ser con mayúscula.
• Los comentarios son en cursiva.
• Las descripciones en lenguaje natural.

INPUT N, x1, x2, …, xn .


N
OUTPUT SUMA=
xi
xi .

STEP 1 Set SUMA = 0. (Initialize accumulator)


STEP 2 For i = 1, 2, …, N (loop)
Set SUMA = SUMA + xi. (Add the next term.)
STEP 3 OUTPUT (SUMA);
STOP.

Heetae Kim, Ingeniería Civil Industrial Taller de Análisis Numérico


Estabilidad de los algoritmos

• Si un cambio pequeño en las entradas produce un cambio pequeño en las


salidas se dice que los algoritmos son estables.

• Si producen grandes cambios (O que no puedan ser determinados) entonces


se dice que son inestables.

• Si un algoritmo es estable solo por un grupo particular de elementos se dice


que es condicionalmente estable.

Heetae Kim, Ingeniería Civil Industrial Taller de Análisis Numérico


Estabilidad de los algoritmos

• Si En ≈ CnE0,
donde C es una constante independiente de n,entonces se dice que el
crecimiento del error es lineal.

• Si En ≈ CnE0
para un C> 1, entonces el crecimiento del error se le llama exponencial.
1.3 Algorithms and Convergence 35

Figure 1.12
En

Unstable
Unstable exponential
exponential error growth
growth
n
En ! C E0

E0 > 0: Error inicial


En: Magnitud del error
después de n operaciones Stable
Stable linear
linear errorgrowth
growth
E n ! CnE 0

E0

1 2 3 4 5 6 7 8 n

Heetae Kim, Ingeniería Civil Industrial Taller de Análisis Numérico


brief discussion
general, we would of
likesome
the terminology
technique to used to describe
converge as the rate
rapidly asatpossible.
which1.3 convergence
The follow
Algorithm
general,
In general, In
we would wegeneral, like the
would welikewould
technique
the like the technique
to converge
technique to to converge
as rapidly
converge as as
as possible.
rapidly rapidly
as The
possible.asfollow
possTh
In general, we would like the technique to converge as rapidly as possible. The fo
Tazas
finition
ntains the
efinition is dedefinition
used
true
is used
definition
definition isis used
convergencia
to
value.
to
used compare
compare the
Unfortunately,
iscompare
used
totocompare
convergence
the to a very
compare
convergence
theconvergence
the
rates
small of
the convergence
convergence sequences.
interval may
sequences.
rates
rates
be needed
rates of sequences.
of sequences.
of sequences.
lementation.

an interval that contains the true value. Unfortunately, ∞
a very sm
ppose {β }}nn=1 isis}∞∞aque sequence ∞ known to converge and {αto }nn=1 converges
ition
uppose 1.18

Suppose

{βnSupongaSuppose
{β a {β
sequence
is a } is
known
es
sequence a
una sequence
secuencia
known known
que
to to
converge to converge
zero,
converge a
to and
0 y {α
zero, } ∞
nand zero, and∞α. {αn}t
converges
hacia
{α }
for reasonable implementation. =1 con
n n n=1 n =1 ∞
Suppose
ergence {β
=1
n n} n=1 is a sequence known to converge to zero, and {αn} n nconverg
mber
umber α.IfIfaaα.
α.
number positive
number
positive
If
n
a
=1 constant
constant
α.
positive K exists
K
If aconstant
positiveexists K with
constant
exists K
withexists with n=1
numberSi α. unaIfconstante
a positivepositiva constant K exists
K existe tal quewith
niques involving sequences Rates|α of
are Convergence
often used, this section concludes with a n,
|α n−α|
−α| ≤ K|β |α|, −α|for large
≤ K|β n, |, for large
n
|α|α n −α|
n −α| ≤≤n n
K|β K|β |, fornfor
n|,,npara
nlarge
large
grande, n, n,
some terminology used to describe the rate at which convergence occurs.
n we say that {α } ∞ ∞Since iterative
converges to ∞techniques
with involving
rate, or order,sequences
of are
convergence often used, th(O
en we
uld then say
like the
we
we that {α
then
technique
say that
say
entonces:, n
thatn }
we
nn“=1{α

=1 toconverges
say
} ∞
} that
converge
∞ {α to
}
n as
converges
converges
converge n α
=1 converges
rapidly
to
haciato
α as
with
αα with
con to
possible.
rate,
una α
rate,with
or
taza The
or rate,
order,
de
convergence
ofor
following
order, of
convergencia order, ofO(β
O(β
convergence
convergence
O(β )”.conver
n
n ).
).
O(β (T
pression isisthe
read brief
nnn=1discussion
n=1 of some terminology used =αto describe
+α the
n
rate at n
xpression
o compare
expression
expression read isis“big
“big
expression
convergence
read
read oh
oh of
ofoh
is
“big
“big read
n
ohn”.)
ββrates
ofofβIt
”.)“big
of
β
issequences.
It ”.) indicated
oh
”.)
It ofis
It
is ”.)by
It writing
βnindicated
indicated isby
In general, we nwould like the technique to converge
n by αnn =
indicated
writing
writing by
n
+
α n
O(β
O(β
writing
αα =
= + αnα).n =). α +
n).
+
O(β O(β
as rapidly
n n).
definition is used to compare ∞ the∞convergence
∞ rates of sequence
Although
Although
s a sequence • Aunque
Although Definition
Definition
knownlaAlthough
to
Definition1.18
1.18 permits
permits
Definition
converge
definición anterior
1.18 to {α
zero,
permites
permits }
1.18
n n{α and
que to
permits
} ∞ be

∞to compared
} {α
be } with
with
to
converges
sea be
comparada
ncompared an
an
to
with arbitrary
arbitrary
compared
acon
an una seque
seque
with
arbitrary anse
∞∞ Although∞Definition 1.18 permits {αnn=1 =1 n }n=1 to be compared with an arbitra
n n =1 n=1
}}nn=1
βnitive
n {β
=1, ,in
in
constant
} ∞
∞ nearly
nearly
, in{β
K every
every
}
exists
nearly
n , situation
situation
in nearly
with
every we use
we
every
situation wesituation
use we use
{β }
Definition
n n
n n=1=1 , in nearly
n =1
1.18 arbitraria
secuencia every situation
∞ we
Suppose {βn}n=1 , isenacasi use
sequence known toutilizamos:
cada circunstancia converge to zero, an
|αn −α| ≤number K|βn|, α. forIf alarge
positive 1 1 K exists1 with
n, constant
β n =βnp=, ,1 βn = p ,
nβn = np ,
p
n

αn}n=1 converges
• para un to α with
numero p >rate,
0. En or order,
general, nos ofinteresa |αeln
convergence −α| O(β
n mayor ≤ K|β
valor |,p con:
den(This
n). for large n,
rsome
“bigsome
for
oh number
number
some
of β for ppsome
number
”.) It > 0.0.number
We0.are
We
> indicated
is p > are
We
bygenerally
>
are 0.
generally
p We
generally
writing αinterested
are= generally
interested
α + in the
O(β in
). largest
interested
largest
the value
largest in
value of
the
of
value pwith
largest
pwith
of pwi va
ααn
++O(1/n for
O(1/n some
pp n number p p
). αp+ O(1/n then >we
). 0. We
say are
that {α generally
} ∞n
⎛ ⎞interested
converges
1
n
to α inwith
the rate,
largestor value
order, ofofp
α + O(1/n ).
). an = a +nO
n =1⎜
p⎟
α + O(1/np). expression is read “big oh⎝ n of⎠ βn”.) It is indicated by writing αn

nition 1.18 permits {αn}n=1 to be compared with an arbitrary sequence
uppose
xample
ppose
every that,
that,
Suppose 2 for
situation for
that, n≥
Suppose
n≥
we for 1,
1,
use n≥ that,
1, for n≥ 1,
Suppose that, for n≥ 1,
Although Definition 1.18 permits {α } ∞
n n=1 to be compared
Heetae Kim, Ingeniería Civil Industrial
n+
n+ 1 1
Taller de Análisis Numérico
n+ 1n+ 3 n+ 3 n+ 3
xample 2 Suppose that, for n≥ 1,
Tazas de convergencia
n+ 1 n+ 3
αn = and α̂n = .
n2 n3
Ejemplo : ¿Cual es la taza de convergencia de las siguientes secuencias?
Both limn→∞ αn = 0 and limn→∞ α̂n = 0, but the sequence {α̂n} converges to this limit
much faster than the sequence {αnn}.+Using
1 five-digit rounding
! +3
narithmetic we have the values
a =
shown in Table 1.7. Determine
n rates Y
2 of convergence
a =
forn these two
3 sequences.
n n
Table 1.7
n 1 2 3 4 5 6 7

αn 2.00000 0.75000 0.44444 0.31250 0.24000 0.19444 0.16327


α̂n 4.00000 0.62500 0.22222 0.10938 0.064000 0.041667 0.029155

• Ambas secuencias convergen a 0 pero a!n es mas “rápida”.


ther ways
wth of • Define the sequences βnn+=11/nand
Entonces:
Solution n + nβ̂n =2n
an − 0 =
1
1/n2 . Then
= 2 ⋅≤ = O
⎛ 1⎞
=
ns, some of n2n+ 1 n2 n+ nn2 n ⎜⎝ n ⎟⎠
1
both above |αn −0| = ≤ = 2 · = 2βn
ce or ! n + 3 n + 3n 4n
n2 n2 n 1 ⎛ 1⎞
eration. and
an − 0 = 3 ≤ = 3 = 4⋅ 2 = O⎜ 2 ⎟
nalyzes
n n 3
n n ⎝n ⎠
le [CLRS], n+ 3 n+ 3n 1
tal que: |α̂n −0| = ≤ = 4 · = 4β̂n.
mation. n3 n3 n2
⎛ 1⎞ ! ⎛ 1⎞
an = 0 + O ⎜ ⎟ y an = 0 + O ⎜ 2 ⎟
⎝ n⎠ ⎝n ⎠
ning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Heetae Kim, Ingeniería Civil Industrial Taller de Análisis Numérico
y suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Tazas de convergencia de funciones

• Este método también puede ser aplicado a las formulas.

• Supoga F(h) con lim F(h) = L y G(h) con lim G(h) = 0.


h→0 h→0

Si K existe tal que | F(h) − L | ≤ K | G(h) | ,

para un h pequeño entonces: F(h) = L + O(G(h)) .

• En general para las comparaciones usamos la forma de G(h) = hp.

Heetae Kim, Ingeniería Civil Industrial Taller de Análisis Numérico


1.3
Ejemplo
an interval that contains the true value. Unfortunately, a
for reasonable implementation.
• Calcule el tercer polinomio de la serie de Taylor de cos h:

Rates 1of2 Convergence


1 4
cos h = 1− h + h cos ξ (h)
2 24
Since iterative techniques involving sequences are often
brief
Para un numero ξ(h) entre ) y discussion
h. of some terminology used to describe th
In general, we would like the technique to converge as
Esto implica que, definition
1 2 is 1used to compare the convergence rates of
cos h + h = 1+ h cos ξ (h)
4

2 24

Definition⎛ 1.18 1 Suppose⎞ {β
1 n } n=1 is a4 sequence
1 4 known to converge to
⎜⎝ cos h + 2 number
h ⎟ −1 =
2
cos ξ (h) h ≤ h
⎠ 24 a positive constant
α. If 24 K exists with

|αn −α| ≤ K|βn|, for la


De este resultado,
then we say that {αn}∞ n=1 converges to α with rate, or o
1
cosexpression is O(h
h + h 2 = 1+ read4 )“big oh of βn”.) It is indicated by wr
2

Although Definition 1.18 permits {αn}∞ n=1 to be co


Heetae Kim, Ingeniería Civil Industrial
{βn}∞Taller
, inde Análisis Numérico
nearly every situation we use

You might also like