Vous êtes sur la page 1sur 5

DEPARTAMENTO DE CIENCIAS

EXACTAS
MÉTODOS NUMÉRICOS
TEMA:
FORO
INTEGRANTES:
Robinson Chiluisa
Jhon Unda

NRC: 3212
30 de junio de 2018
UNIVERSIDAD DE LAS FUERZAS ARMADAS - ESPE
DEPARTAMENTO DE CIENCIAS EXACTAS
NRC: 3212 Métodos Numéricos R Chilusa, J Unda
Implemente un código que permita determinar la ecuación de ajuste lineal
y logarítmica (y = ao +a1 ·Ln(x)), para los nodos Po(1; 1), P1(2; 1.5); P2(3; 1.8)
y P3(5; 2). Además, presente el gráfico y la evolución del error para modelos
de ajuste planteados determinando el mínimo y máximo error en el intervalo
analizado.
Análisis

Ajuste Lineal

y = ao + a1 · Ln(x)
n
X n
X
y i = n · ao + a1 · xi
i=0 i=0
n
X n
X n
X
x i · y i = ao · x i + a1 · (xi )2
i=0 i=0 i=0

Ajuste logarítmico

y = ao + a1 · ln(x)
n
X n
X
yi = n · ao + a1 · ln(x)
i=0 i=0
n
X n
X n
X
x i · y i = ao · x i + a1 · xi · ln(x)
i=0 i=0 i=0

Tabla de valores

xi yi xi · yi (xi )2 ln(xi ) xi · ln(xi )


1 1 1 1 0 0
2 1.5 3 4 ln(2) 2ln(2)
3 1.8 5.4 9 ln(3) 3ln(3)
5 2 10 25 ln(5) 5ln(5)
=11 =6.3 =19.4 =39 =ln(30) =ln(337500)

Con lo que se obtiene las siguiente ecuaciónes:

y = 1,05238 + 0,614628 · ln(x)

y = 0,922857 + 0,237143 · x
Código
1 %Integrantes : Robinson Chiluisa , Jhon Jairo Unda
2 %NRC : 3212
3 %Foro 2
4 % Programa para determinar la ecuacion de ajuste lineal y
logaritmica
5 function [ ELineal ELogaritmica ]= Aj uste Lin eal_ Loga ritm ica (x ,
y)
UNIVERSIDAD DE LAS FUERZAS ARMADAS - ESPE
DEPARTAMENTO DE CIENCIAS EXACTAS
NRC: 3212 Métodos Numéricos R Chilusa, J Unda

6 %[ ELineal ELogaritmica ]= Aju ste Line al_L ogar itmi ca ([1 2 3 5] ,[1
1.5 1.8 2])
7 n = length ( x ) ;
8 SUMx =0;
9 SUMy =0;
10 SUMxy =0;
11 SUMx2 =0;
12 SUMlnx =0;
13 SUMxlnx =0;
14

15 for i =1: n
16 %Sumatorias
17 SUMx = SUMx + x ( i ) ;
18 SUMy = SUMy + y ( i ) ;
19 SUMxy = SUMxy + x ( i ) * y ( i ) ;
20 SUMx2 = SUMx2 +( x ( i ) ) ^2;
21 SUMlnx = SUMlnx + log ( x ( i ) ) ;
22 SUMxlnx = SUMxlnx + x ( i ) * log ( x ( i ) ) ;
23 endfor
24 %codigo para la ecuacion de regresion lineal
25 A =[ n SUMx ; SUMx SUMx2 ];
26 a =[ SUMy SUMxy ];
27 [ Aa C ]= Gauss (A ,a ’) ; %llamamos a Gauss
28 B=C;
29 B (1 ,1) = C (1 ,2) ;
30 B (1 ,2) = C (1 ,1) ;
31

32 %Codigo para la ecuacion de regresion logaritmica


33 D =[ n SUMlnx ; SUMx SUMxlnx ];
34 d =[ SUMy SUMxy ];
35 [ Dd E ]= Gauss (D ,d ’) ; %llamamos a Gauss
36 F=E;
37 F (1 ,1) = E (1 ,2) ;
38 F (1 ,2) = E (1 ,1) ;
39 %Para graficar y obtener el error
40

41%comparacion
42 x1 = min ( x ) :0.01: max ( x ) ;
43 p = inline ( ’B (1 ,1) * x1 + B (1 ,2) ’ , ’ x1 ’) ;

44 y1 = p ( x1 ) ;

45 q = inline ( ’F (1 ,1) * log ( x1 ) + F (1 ,2) ’ , ’ x1 ’) ;

46 y2 = q ( x1 ) ;

47 %Graficas

48 plot ( x1 , y1 , ’r ’ ,x1 , y2 , ’k ’)

49 %Error max y Error min

50 R = y2 - y1 ;

51 ERRORmax = max ( abs ( R ) )

52 ERRORmin = min ( abs ( R ) )

53 pause (3) %evita que las graficas salgan seguidas

54 figure (2)

55 semilogy ( abs ( R ) , ’g ’) ;
UNIVERSIDAD DE LAS FUERZAS ARMADAS - ESPE
DEPARTAMENTO DE CIENCIAS EXACTAS
NRC: 3212 Métodos Numéricos R Chilusa, J Unda

56 title ( ’ EVOLUCION DEL ERROR ’)


57 %Ecuaciones
58 ELineal = polyout (B , ’x ’) ;
59 ELogaritmica = polyout (F , ’ log ( x ) ’) ;
60

endfunction
61

Ejecución

Evolución del Error


UNIVERSIDAD DE LAS FUERZAS ARMADAS - ESPE
DEPARTAMENTO DE CIENCIAS EXACTAS
NRC: 3212 Métodos Numéricos R Chilusa, J Unda

Vous aimerez peut-être aussi