Академический Документы
Профессиональный Документы
Культура Документы
AULA 3
Exerccios
- Simulao de modelos discretos
Objetivos da Aula
- Aprender function - Simular modelos discretos - uso de variveis globais. - uso de modelos estocsticos.
Criar e salvar um programa em Matlab onde est a funo. C s v u p og e b o de es u o. Programar o algoritmo principal do problema. Ligar o principal com a function usando type
function Programa g
Principal
nome_da_function=...calculo da funo...
A function do problema
Programa Principal
dx = f (t , x ) dt x ( t 0 ) = x0
Aula 3- Prof. Dr. Marco Antonio Leonel Caetano 7
PONTO DE TANGNCIA
x dx
dt
TEMPO (t)
Aula 3- Prof. Dr. Marco Antonio Leonel Caetano 8
Sistemas Discretos
dx = f (t , x ) dt x (t0 ) = x0
x dx = Lim = f ( t, x ) dt t 0 t
x k +1 x k = f (t k , x k ) t k +1 t k
x k +1 x k = f ( t k , x k )
x k +1 = x k + f ( t k , x k )
Problema Exemplo
x k +1 = x k 0.1x
Com as condies iniciais: t(0) = 0 x(0) = 1 ( ) tempo final = 15
2 k
10
A function do problema
11
Programa Principal
Chamada da function
12
Resultado da simulao
13
Mtodo de Newton-Raphson
f ( xk ) xk +1 = xk f ' ( xk )
Onde f() o polinmio e f() a derivada.
14
Problema 2
Encontrar as razes do polinmio abaixo no Matlab (usando function), pelo mtodo de Newton: ( d f ti ) l t d d N t
f ( x) = x 5 x + 6
2
15
Algoritmo
1- chutar 1 h t a semente x0. t 2- h 2 chamar a f function d funo f( ) ti da f f(x). 3- h 3 chamar a f function d d i d f( ) ti da derivada f(x). 4- calcular no o 4 calc lar o novo xk+1. 5 5- calcular a diferena entre o novo xk e antigo xk+1. 6 6- fazer o antigo x igual ao novo.
Aula 3- Prof. Dr. Marco Antonio Leonel Caetano 16
Arquivo ff.m A i ff
f ( x) = x 5 x + 6
2
Arquivo ffL.m
f ' ( x) = 2 x 5
17
Programa Principal
Chute inicial
18
Com x0 = 0 ...
Com x0 = 10 ... C 0
19
Chute inicial
20
x(0) = 0
x(0) = 10
21
Problema 3
xk +1 = 5sen(0.1xk ) e 0.001xk
Com as condies iniciais: t(0) = 0 x(0) = 1 ( ) tempo final = 15
22
A function do problema
23
Programa Principal
24
Resultado da simulao
25
Modelo
x k +1 = 1.875 + 0.25x k + 0.375 y k y k +1 = 10 2 x k + 0.5 y k x(0) = 2.5 y(0) = 15
26
A function do sistema
27
Programa Principal
28
Subplot(211)
Subplot(212)
Figure 2
29
Problema 4
30
A function do sistema
31
Resultado da simulao
32
O matlab possui geradores de nmeros aleatrios conforme a distribuio de probabilidade desejada. Distribuio Uniforme : i i i i rand d
Distribuio Gaussiana : randn Faz-se necessrio antes a busca de uma semente para g p gerao de nmeros aleatrios. Antes do uso das funes, gera-se a semente da seguinte forma: Uniforme: U if rand(seed, sum(100*clock)) d( d (100* l k)) Gaussiana: randn(seed, sum(100*clock))
Aula 3- Prof. Dr. Marco Antonio Leonel Caetano 33
34
Busca da semente
35
A incerteza no modelo
36
A function modificada
Desvio-padro D i d
37
O resultado
38
Variveis Globais
So Variveis cujo valores so recebidos no programa principal, mas reconhecidos pelas subrotinas ou functions chamadas durante a execuo.
Comando
39
B C (t c t ) y ( t ) = A + B (t c t ) + cos( ln (t c t ) + ) (t c t )
Exemplo
A = 20000; B = -6; C = 19; = 1.33; = 20; = 5.9
tc=242
40
41
Usando Matlab
Variveis globais
42
Na Function
43
xk +1 = xk + k +1
=0 = desvio da srie tamanho da srie
45
1.3
1.2 12
1.1
0.9
0.8
FUTURO U U O ??????
0.7
0.6
500
1000
1500
2000
2500
46
Intervalo de Confiana
Forecasting
2.5
1.5
0.5 05
95%
68%
-0.5
500
1000
1500
2000
2500
3000
48
Forecasting
1.6 1.4 1.2 1 0.8 0.6 0.4 0.2 0
500
1000
1500
2000
2500
3000
49
Forecasting
1.05
0.95
0.9
0.85
0.8 08
0.75 1900 2000 2100 2200 2300 2400 2500 2600 2700 2800 2900
Aula 3- Prof. Dr. Marco Antonio Leonel Caetano 50
1.1 1.05 1 0.95 0.9 0.85 0.8 0.75 0 75 0.7 2000 2100 2200 2300 2400 2500 2600 2700 2800 2900
Tempo (minutos)
Aula 3- Prof. Dr. Marco Antonio Leonel Caetano 51
O Programa
52
xk +1 = + xk + k +1
= = desvio da srie tamanho da srie
53
O CASO BOVESPA
REGIO DE INTERESSE
8 7 6 5 4 3 2 1 0 x 10
4
BOVESPA
Supor
= 40
500
1000
1500
2000
2500
3000
54
Ateno: como existe drift ao invs da mdia (que fixa), toma-se cada dado da iterao.
55
x 10
500
1000
1500
x 10
Escolhendo o ltimo dado (fixo) existe uma tendncia que o intervalo no acompanha.
56
500
1000
1500
57
k 2 k=2 max(2),min(2)
500
1000
1500
58
k=n max(n),min(n)
500
1000
1500
59
9 8 7 6 5 4 3 2 1 0
500
1000
1500
60
DADOS REAIS
500
1000
1500
61
O PROGRAMA
62
63