Algoritmos Métodos Numericos

24
1 División Académica de ingeniería y Arquitectura (DAIA) Asignatura: Métodos Numéricos Tarea: Programas Alumnos: Héctor Manuel Ramírez López Edgar Jesús García Avendaño Fernando Hernández Moreno Profesor: José Luis Jiménez León

description

Programación de métodos de aproximacion

Transcript of Algoritmos Métodos Numericos

Page 1: Algoritmos Métodos Numericos

1

División Académica de ingeniería y Arquitectura

(DAIA)

Asignatura:

Métodos Numéricos

Tarea:

Programas

Alumnos:

Héctor Manuel Ramírez López

Edgar Jesús García Avendaño

Fernando Hernández Moreno

Profesor:

José Luis Jiménez León

Fecha:

30/11/2012

Page 2: Algoritmos Métodos Numericos

1

BISECCION--------------------------------------------------------------- (3-4)

SECANTE------------------------------------------------------------------ (5-7)

ELIMINACION DE GAUSS--------------------------------------------- (8-11)

MATRIZ INVERSA------------------------------------------------------- (12-14)

MINIMOS CUADRADOS----------------------------------------------- (15-17)

Page 3: Algoritmos Métodos Numericos

1

consteuler=2.718281828;varx1,xu,xm,Xma,fx1,fxm,e,xr:real;beginx1:=strtofloat(edit1.text);xu:=strtofloat(edit2.text);e:=0;Xma:=0;Repeatxm:=(x1+xu)/2;e:= ((Xma – Xm)/Xm) *100;fx1:=exp(-x1*Ln(euler))-x1;fxm:=exp(-xm*Ln(euler))-xm;xr:=fx1*fxm;Xma:=Xm;if xr>0thenx1:=xm;elsexu=xm;until (abs(e)<5);edit3.text:=floattostr(xm);end;

Valor de X1Valor de XUXma 0RepetirXm (X1 + Xu)/2Error ((Xm ant – Xm act)/Xm act) *100Fx1 Fxm Xr FX1 * FXmXma XmSi Xr > 5EntoncesX1 XmDe lo contrarioXu XmHasta error<5Imprimir Xm

Page 4: Algoritmos Métodos Numericos

1

INICIO

N, Xi,Xu,f(x)

xi←xm

xu←xm

f(xi)*f(xm)>0

Si

Si

Xm

Fin

No

No

Page 5: Algoritmos Métodos Numericos

1

VarX1,X2,X3, error :real;BeginX1:= StrTofloat(Edit1.Text);X2:= StrTofloat(Edit2.Text);RepeatFx1:= (Exp(-x1*(Ln(e))))-x1;Fx2:= (Exp(-x2*(Ln(e))))-x2;X3:= (xi-((Fx1*(x2-X1)))/(Fx2-Fx1));Fx3:= (Exp(-x3*(Ln(e))))-x3;error:= (abs((x2-x3)/x3))*100;X1:= x2;X2:= X3;Until error<5;Edit3.text:= FloatToStr(x3);End;

Coeficientes de la ecuaciónValor de X1Valor de X2Repetirf(x1)f(x2)X3 (x1-((Fx1*(x2-X1)))/(Fx2-Fx1));F(X3)Error ((X2 – X3)/X3)*100)X1 X2X2 X3Hasta Error < 5Imprimir X3

Page 6: Algoritmos Métodos Numericos

1

f(xi), f(Xi-1), n+1Xi+1

INICIO

N, Xi, Xi-, f(x)

Si

Xi-1

Fin

Xi= Xi+1

Xi-1= Xi+1

N=

10No

Page 7: Algoritmos Métodos Numericos

1

Grado de la ecuación N

Coeficientes de la ecuación 0<=i<=n

Tolerancia tolValor de X1Valor de X2Y1 f(x1)Y2 f(x2)Contador 0RepetirX3 X1 + (Y1*(X2-X1)/(Y1+Y2))Y3 F(X3)Si (Y3*Y2) >0EntoncesX1 X3Y1 Y3De lo contrarioX2 X3Y2 Y3Contador contador + 1Hasta (X2-X1) <= tol p (contador>100)

Page 8: Algoritmos Métodos Numericos

1

procedure TForm1.Button1Click(Sender: TObject);

var

A: Array[1..10,1..10] of real;I,K,J,NE: integer;X,Suma: real;

Begin

For I:=1 To 10 Do

For K:=1 TO 10 Do

A[I,K]:= StrToFloat(StringGrid1.Cells[K,I]);

NE:= StrToInt(Edit1.text);

For I:=1 To NE Do

For J:=I+1 To NE Do

For K:= I+1 To NE+1 Do

A[J,K]:= A[J,K]-(A[I,K]/A[I,I])*A[J,K];

X:= A[NE,NE]+1/A[NE,NE];

For I:= NE-1 To 1 Do

Suma:= 0;

For K:= I+1 To NE Do

Suma:= Suma+A[I,K]*X[K];

For I:=1 To NE Do

X[I]:= 1/A[I,I]*(A[I,NE+1]-Suma);

For I:=1 To NE Do

StringGrid1.Cells[I,5]:= FloatToStr(X[I]);

Page 9: Algoritmos Métodos Numericos

1

end;.

Page 10: Algoritmos Métodos Numericos

1

INICIO

[A], NE

I=1

J=I+1

K=I+1

a[j,k] ←a [j,k]-[a[I,k]/a[I,i])*a[j,k]

K=I + 1

J= J + 1K ≤ NE

+1K= K + 1

J ≤ NE

I ≤ NE

I= I + 1

J= I + 1

K= I + 1

x= aNE + 1/aNE,NE

Si

Page 11: Algoritmos Métodos Numericos

1

Suma= 0I= NE - 1

K= I + 1

Suma= suma + (a[i,k]*x[k])

K ≤ NE K= I + 1

I= J + 1

I ≤ 1

I=1

XI= 1/a[I,I]*(aINE+1-suma)

I ≤ NE I= I + 1

X1

FIN

K= k + 1

Si

Si

Si

No

No

Page 12: Algoritmos Métodos Numericos

1

Numero de ecuaciones n Matriz aumentada 1<= i<=n i<=k<=n+1

Hacer I de 1 hasta NE-1 Hacer J de I+1 hasta NE Hacer K de I+1 hasta NE+1

- / *

, /Hacer I de NE-1 hasta 1Suma0 Hacer K de I+1 hasta NESuma Suma + *1/ ( ,NE+1-Suma)

Imprimir

Page 13: Algoritmos Métodos Numericos

1

Var

A,B: Array[1..10,1..10]of real;

I,K,J,NR: Integer;

begin

NR:= StrToInt(Edit1.Text);

For I:=1 To NR Do

For K:=1 To NR*2 Do

A[I,K]:= StrToFloat(StringGrid1.Cells[K,I]);

For I:=1 To NR Do

Begin

For K:=1 To NR Do

If K<>I

Then

Begin

For J:=I+1 To NR*2 Do

A[K,J]:= A[K,J]-((A[I,J]/A[I,I])*A[K,I]);

A[K,I]:= A[K,I]-((A[I,I]/A[I,I])*A[K,I]);

end;

For J:=I+1 To NR*2 Do

A[I,J]:= A[I,J]/A[I,I];

A[I,I]:= A[I,I]/A[I,I];

End;

For I:=1 To NR Do

For K:=1 To NR*2 Do

StringGrid2.Cells[K,I]:= FloatToStr(A[I,K]);

end;

Page 14: Algoritmos Métodos Numericos

1

INICIO

[A], NR

I=1

K ← I + 1

J ← I + 1

K=I+1

a[k,j] ←a [k,j]-[a[I,k]/aII)*a[k,j]

K ≤ NR K= K + 1

J ≤ NR

I ≤ NR

I= I + 1

K= I + 1

J= I + 1

Si

Si

No

No

No

Si

[A]⁻¹

Fin

Page 15: Algoritmos Métodos Numericos

1

Numero de ecuaciones NEMatriz aumentada ai,K 1<=i<=NE 1<=K<=NE+1*2Hacer I de q hasta NEHacer J de 1 hasta NESi J<>IEntoncesHacer K de I+1 hasta NE+1*2aj,k aj,k-(ai,k/ai,i)*aj,iHacer k de I+1 hasta NE+1*2aj,k ai,k/ai,iHacer I de 1 hasta NEX1<--ai,NE+1Imprimir Xi

Page 16: Algoritmos Métodos Numericos

1

VAR

N,I:INTEGER;

X:ARRAY[1..10]OF REAL;

Y:ARRAY[1..10]OF REAL;

FY:ARRAY[1..10]OF REAL;

A1,A0,PX,PY,SX,SY,XY,SX2:REAL;

begin

N:=STRTOINT(EDIT1.TEXT);

FOR I:=1 TO N DO

BEGIN

X[I]:=STRTOFLOAT(STRINGGRID1.Cells[1,I]);

Y[I]:=STRTOFLOAT(STRINGGRID2.Cells[1,I]);

END;

SX:=0;

SY:=0;

XY:=0;

FOR I:=1 TO N DO

BEGIN

SX:=SX+X[I];

PX:=SX/N;

SY:=SY+Y[I];

PY:=SY/N;

XY:=XY+(X[I]*Y[I]);

END;

Page 17: Algoritmos Métodos Numericos

1

SX2:=0;

FOR I:=1 TO N DO

SX2:=SX2+SQR(X[I]);

A1:=(N*XY-SX*SY)/(N*SX2-SQR(SX));

A0:=PY-(A1*PX);

FOR I:=1 TO N DO

BEGIN

FY[I]:=A0+(A1*X[I]);

STRINGGRID3.Cells[1,I]:=FLOATTOSTR(FY[I]);

EDIT2.Text:= FLOATTOSTR(A0);

EDIT3.Text:= FLOATTOSTR(A1);

END;

end;

Page 18: Algoritmos Métodos Numericos

1

ai

INICIO

X, Y, n

Xi, Yi

Fin

y0=a0 +

a1X