Professional Documents
Culture Documents
Chiapas
Facultad de Ingeniera
Ingeniera Civil
Programacin
Por Alumnos de 2 A
NDICE
11.
12.
13.
14.
15.
1. Mtodo de Biseccin
[a;c].
[c;b].
Si ocurre la primera opcin, o bien la segunda, entonces se ha encontrado
un intervalo de mitad de ancho que el original que contiene una raz. Para
continuar el proceso, se renombra el nuevo intervalo ms pequeo como [a;b] y
se repite el proceso hasta que el intervalo sea tan pequeo como se desee.
Puesto que el proceso de biseccin genera una sucesin de intervalos
encajados, con sus correspondientes puntos medios, se usar la siguiente
notacin para tener registro de los detalles del proceso:
converge
porque
es
2
bn+1-an+1
= (bn-an)/2, n1
n-an)=
(1) Dado que r (la raz buscada) est en una de las dos mitades del
intervalo [an, bn], la distancia del punto medio del intervalo a r debe ser
menor o igual que la mitad de la longitud del intervalo.
(2) Por la igualdad demostrada en (*)
Ventajas y desventajas:
Una gran ventaja de este mtodo es que siempre converge para
funciones continuas f(x). Adems, proporciona el tamao exacto del intervalo
en cada iteracin (en ausencia de errores de redondeo). Para aclarar esto, se
puede observar que en este mtodo despus de cada iteracin el tamao del
intervalo se reduce a la mitad; despus de n iteraciones, el intervalo original se
3
Orden de convergencia
Un algoritmo converge linealmente si existe una constante positiva K<1 tal
Comprobacin de la convergencia
4
As, el proceso iterativo producir puntos Pi= (xi; f(xi)) hasta que el ltimo
punto Pn se encuentre en la banda horizontal comprendida entre las rectas de
ecuaciones y= e y=-.
Esta programacin nos ayudara a encontrar una sola raz real de un polinomio
en caso de que exista y para ya no seguir haciendo laboriosos procedimientos
en esta interfaz es muy til porque solo introducimos el polinomio y despus de
unas cuantas iteraciones nos dice la raz. En caso de que este mtodo no
funcione hay muchos tipos de mtodos para encontrar una raz de un
polinomio.
Cdigos de programacin:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include "Unit3.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
#include <math.h>
double a,b,c,d,e,p,q,Fx1,Fx2,Fx3,Fx4,Fx5,Fxl,Fr,Fxm,r,prod, i=1,x,h,t,j,l,m,
inicio,k,y,por;
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
//hablitando grafica
Button1->Enabled=true;
a=Edit1->Text.ToDouble();
b=Edit2->Text.ToDouble();
c=Edit3->Text.ToDouble();
d=Edit4->Text.ToDouble();
e=Edit5->Text.ToDouble();
p=Edit6->Text.ToDouble();
q=Edit7->Text.ToDouble();
h=Edit8->Text.ToDouble();
t=Edit9->Text.ToDouble();
j=Edit10->Text.ToDouble();
Fx1=a*(pow(p,4))+b*(pow(p,3))+c*(pow(p,2))+d*p+e;
Edit11->Text=AnsiString(Fx1);
Fx2=a*(pow(q,4))+b*(pow(q,3))+c*(pow(q,2))+d*q+e;
Edit12->Text=AnsiString(Fx2);
Fx3=a*(pow(h,4))+ b*(pow(h,3))+c*(pow(h,2))+d*h+e;
10
Edit13->Text=AnsiString(Fx3);
Fx4=a*(pow(t,4))+b*(pow(t,3))+c*(pow(t,2))+d*t+e;
Edit14->Text=AnsiString(Fx4);
Fx5=a*(pow(j,4))+b*(pow(j,3))+c*(pow(j,2))+d*j+e;
Edit15->Text=AnsiString(Fx5);
}
//---------------------------------------------------------------------------
l=Edit16->Text.ToDouble();
Fxl=a*(pow(l,4))+b*(pow(l,3))+c*(pow(l,2))+d*l+e;
m=Edit17->Text.ToDouble();
Fxm=a*(pow(m,4))+b*(pow(m,3))+c*(pow(m,2))+d*m+e;
r=(l+m)/2;
Edit18->Text=AnsiString(r);
Fr=a*(pow(r,4))+b*(pow(r,3))+c*(pow(r,2))+d*r+e;
Label15->Caption=AnsiString(r);
Label13->Caption=AnsiString(i);
i++;
}
11
prod=Fxl*Fr;
Edit19->Text=AnsiString(prod);
por=((m-l)/m)*100;
Edit20->Text=AnsiString(por);
Label16->Caption="Eso es todo Margaritos...!!!";
if(prod >0 ){
Edit16->Text="";
Edit16->Text=AnsiString(r);
}
if(prod <0){
Edit17->Text="";
Edit17->Text=AnsiString(r);
}
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button6Click(TObject *Sender)
{
Form3->Show();
Form3->Canvas->Pen->Color=clGreen;
Form3->Canvas->Pen->Width=2;
Form3->Canvas->PenPos=TPoint(0,350);
Form3->Canvas->LineTo(1300,350);
12
Form3->Canvas->PenPos=TPoint(650,0);
Form3->Canvas->LineTo(650,700);
for(x=-30;x<=30;x++){
Form3->Canvas->PenPos=TPoint(650+x*10,355);
Form3->Canvas->LineTo(650+x*10,345);
for(y=-30;y<=30; y++){
Form3->Canvas->PenPos=TPoint(645,350+y*10);
Form3->Canvas->LineTo(655,350+y*10);
}
Form3->Canvas->Pen->Color=clYellow;
Form3->Canvas->Pen->Width=2;
x=-650;
Form3->Canvas->PenPos=TPoint(650+x,35010*(a*pow(x/10,4)+b*pow(x/10,3)+c*pow(x/10,2)+d*x/10+e));
for(x=-650;x<=650;x++){
Form3->Canvas->LineTo(650+x,35010*(a*pow(x/10,4)+b*pow(x/10,3)+c*pow(x/10,2)+d*x/10+e));
}
}
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button4Click(TObject *Sender)
{
a=0;
b=0;
c=0;
13
d=0;
e=0;
p=0;
q=0;
r=0;
h=0;
t=0;
j=0;
Fx1=0;
Fx2=0;
Fx3=0;
Fx4=0;
Fx5=0;
Fr=0;
i=1
Edit1->Text="";
Edit2->Text="";
Edit3->Text="";
Edit4->Text="";
Edit5->Text="";
Edit6->Text="";
Edit7->Text="";
Edit8->Text="";
Edit9->Text="";
Edit10->Text="";
Edit11->Text="";
Edit12->Text="";
Edit13->Text="";
14
Edit14->Text="";
Edit15->Text="";
Edit16->Text="";
Edit17->Text="";
Edit18->Text="";
Edit19->Text="";
Edit20->Text="";
Label13->Caption="";
Label15->Caption="";
Label16->Caption="";
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button5Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
15
Cdigo de programacin:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit3.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
//--------------------------------------------------------------------------__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
16
(tambin
Mtodo
Newton-
Raphson o de Newton-
Fourier). Es un mtodo
grfico y analtico de
de
llamado
optimizacin iterativo, el cual permite encontrar las races de una funcin f(x),
aplicando a propiedad de la derivada.
El valor de la derivada en un punto es igual a la pendiente de la recta tangente que
pasa por ese punto.
17
CASOS ESPECIALES.
o
o
o
Ea = | (Xi-Xi-1/
Xi)* 100|
VENTAJAS.
Robustez
velocidad al encontrar la
raz
No
intervalos,
trabaja
en
sino
en
iteraciones.
Su indicador de efectividad es la repeticin de cifras (convergencia).
DESVENTAJAS.
Lenta convergencia debida a la naturaleza de una funcin en particular.
19
Botn ENTRAR.
Botn SALIR.
x2, x y la constante, el
nuestra
realizara el programa.
Calcula la derivada de la
raz
el
los valores propuestos en las primeras casillas, dentro de una estructura for,
evala a (xn) y a (xn) con el valor inicial, si uno de ellas es = 0 el programa
cargara un error en una venta y determinara que la funcin diverge (debido a
diversos puntos de inflexin de (xn)) y no es posible implementar el mtodo,
Este botn acta como vinculo al Form3, donde se tabulan los siguientes
datos; nmero de iteraciones, valor propuesto y los valores obtenidos
por la ecuacin, la funcin origina evaluada, la funcin derivada
evaluada, el resultado del mtodo evaluado con los 3 datos anteriores a
este, y en el ltimo memo, el porcentaje de error por iteracin.
RadioGroup.
Botn REINICIAR.
Botn YA TENEMOS 10
Cierra la interfaz 2, sin guardar ningn dato, para asi poder a ingresar
nuevamente a l, mediante la interfaz 1.
ALGORITMO.
Algoritmo bsico, del comportamiento del programa:
Newton Raphson.
9. Calcular el error porcentual aproximado.
10. Verificar que se cumpla la condicin |ep|<=Tmax. Si se cumple,
entonces sea encontrado la aproximacin final, si no ir al siguiente paso.
11. Hacer i=i+1.
CDIGO DE PROGRAMACIN.
UNIT 1.
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
//Incluyendo a los Unit 2 y 8
#include "Unit1.h"
#include "Unit2.h"
#include "Unit8.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm" TForm1 *Form1;
//---------------------------------------------------------------------------
void
{
//Vinculacin del interfaz 1 a la 2
Form2->Show();
}
//--------------------------------------------------------------------------void
{
//Botn que cierra el programa por completo
Close();
}
//---------------------------------------------------------------------------
UNIT 2.
//--------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop
//Incuyendo los Unit del 3 al 7
#include "Unit2.h"
#include "Unit3.h"
#include "Unit4.h"
#include "Unit5.h"
#include "Unit6.h"
24
#include "Unit7.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
//Incluyendo el diccionario matemtico
#include <math.h>
//Declarando variables double
double a, b, c, d, e, xn, it, da, db, dc, dd, de,x,y; double xn1, re, err, n, s,fx, dfx,
y1,y2,y3,y4,y5,y6,y7 ;
TForm2 *Form2;
{
//Botn que cierra el interfaz 2
Close();
}
25
//--------------------------------------------------------------------------void
{
// Programando Reset
Edit1->Text="";
Edit2->Text="";
Edit3->Text="";
Edit4->Text="";
Edit5->Text="";
Edit6->Text="";
Edit7->Text="";
Label10->Caption="";
RadioGroup1->Enabled=false;
Button2->Enabled=false;
RadioGroup1->ItemIndex=-1;
Edit1->SetFocus();
}
//--------------------------------------------------------------------------void
26
b=Edit2->Text.ToDouble();
c=Edit3->Text.ToDouble();
d=Edit4->Text.ToDouble();
e=Edit5->Text.ToDouble();
xn=Edit6->Text.ToDouble();
it=Edit7->Text.ToDouble();
//Derivada de la funcin
da=a*4;
db=b*3;
dc=c*2;
dd=d;
de=0;
Form3->Memo3->Clear();
Form3->Memo4->Clear();
Form3->Memo5->Clear();
Form3->Memo6->Clear();
Form3->Memo7->Clear();
RadioGroup1->Enabled=true;
Button2->Enabled=true;
y4=a*pow(xn,4);
y3=b*pow(xn,3);
y2=c*pow(xn,2);
y1=d*xn;
fx=y4+y3+y2+y1+e;
28
// Calculando xn
Form3->Memo2->Lines->Add(xn);//Enviando xn al Memo2
//Calculando la divisin
s=fx/dfx;
29
//calculando xn+1
xn1= xn- s;
Form3->Memo6->Lines->Add(xn1);//Enviando xn+1 al Memo6
}
//--------------------------------------------------------------------------void
{
//Mostrando tabulacin
Form3->Show();
}
//--------------------------------------------------------------------------void
// Grafica Normal
if(RadioGroup1->ItemIndex==0)
Form4->Show();
Form4->Canvas->Pen->Color=clBlack;
Form4->Canvas->Pen->Width=1;
Form4->Canvas->PenPos=TPoint(0,350);
Form4->Canvas->LineTo(1300,350);
Form4->Canvas->PenPos=TPoint(650,0);
Form4->Canvas->LineTo(650,700);
for(x=-65;x<=65;x++)
{
31
Form4->Canvas->PenPos=TPoint(650+x*10,355);
Form4->Canvas->LineTo(650+x*10,345);
}
for(y=-35;y<=35;y++)}
{
Form4->Canvas->PenPos=TPoint(645,350+y*10);
Form4->Canvas->LineTo(655,350+y*10);
Form4->Canvas->Pen->Color=clBlue;
Form4->Canvas->Pen->Width=2;
x=-650;
Form4->Canvas->PenPos=TPoint(650+x,350-10*(a*pow(x/10,4)
+b*pow(x/10,3)+c*pow(x/10,2)+d*x/10+e));
for(x=-650;x<=650;x++)
{
Form4->Canvas->LineTo(650+x,350-10*
(a*pow(x/10,4)+b*pow(x/10,3)+c*pow(x/10,2)+d*x/10+e));
}
// Grafica ZOOM
if(RadioGroup1->ItemIndex==1)
32
Form5->Show();
Form5->Canvas->Pen->Color=clBlack; Form5->Canvas->Pen->Width=1;
Form5->Canvas->PenPos=TPoint(0,350);
Form5->Canvas->LineTo(1300,350);
Form5->Canvas->PenPos=TPoint(650,0);
Form5->Canvas->LineTo(650,700);
for(x=-32;x<=32;x++)
{
Form5->Canvas->PenPos=TPoint(650+x*20,355);
Form5->Canvas->LineTo(650+x*20,345);
}
for(y=-17;y<=17;y++)
{
Form5->Canvas->PenPos=TPoint(645,350+y*20);
Form5->Canvas->LineTo(655,350+y*20);
}
Form5->Canvas->Pen->Color=clBlue;
Form5->Canvas->Pen->Width=2;
x=-650;
Form5->Canvas->PenPos=TPoint(650+x,350-20*
(a*pow(x/20,4)+b*pow(x/20,3)+c*pow(x/20,2)
+d*x/20+e));
33
for(x=-650;x<=650;x++)
{
Form5->Canvas->LineTo(650+x,35020*(a*pow(x/20,4)+b*pow(x/20,3)+c*pow(x/20,2)
+d*x/20+e));
}
//Grafica MEGAZOOM
if(RadioGroup1->ItemIndex==2)
{
Form6->Show();
Form6->Canvas->Pen->Color=clBlack;
Form6->Canvas->Pen->Width=1;
Form6->Canvas->PenPos=TPoint(0,350);
Form6->Canvas->LineTo(1300,350);
Form6->Canvas->PenPos=TPoint(650,0);
Form6->Canvas->LineTo(650,700);
}
for(x=-16;x<=16;x++)
{
Form6->Canvas->PenPos=TPoint(650+x*40,355);
Form6->Canvas->LineTo(650+x*40,345);
}
34
for(y=-8;y<=8;y++)
{
Form6->Canvas->PenPos=TPoint(645,350+y*40);
Form6->Canvas->LineTo(655,350+y*40);
}
Form6->Canvas->Pen->Color=clBlue;
Form6->Canvas->Pen->Width=2;
x=-650;
Form6->Canvas->PenPos=TPoint(650+x,35040*(a*pow(x/40,4)+b*pow(x/40,3)+c*pow(x/40,2)
+d*x/40+e));
for(x=-650;x<=650;x++)
{
Form6->Canvas->LineTo(650+x,35040*(a*pow(x/40,4)+b*pow(x/40,3)+c*pow(x/40,2)
+d*x/40+e));
}
}
//---------------------------------------------------------------------------
UNIT 3.
//--------------------------------------------------------------------------35
#include <vcl.h>
#pragma hdrstop
#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm" TForm3 *Form3;
//---------------------------------------------------------------------------
{
//Botn cerrar
Close();
}
//-------------------------------------------------------------------------UNIT 4.
//--------------------------------------------------------------------------#include <vcl.h>
36
#pragma hdrstop
#include "Unit4.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm" TForm4 *Form4;
//--------------------------------------------------------------------------fastcall TForm4::TForm4(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------void
{
//Botn cerrar
Close();
}
//--------------------------------------------------------------------------UNIT 5.
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit5.h"
//--------------------------------------------------------------------------37
#pragma package(smart_init)
#pragma resource "*.dfm" TForm5 *Form5;
//--------------------------------------------------------------------------fastcall TForm5::TForm5(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------void
{
//Botn cerrar
Close();
}
//--------------------------------------------------------------------------UNIT 6.
//--------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop
#include "Unit6.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm" TForm6 *Form6;
//--------------------------------------------------------------------------38
{
//Botn cerrar
Close();
}
//-----------------------------------------------------------------------UNIT 7.
//--------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop
#include "Unit7.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm" TForm7 *Form7;
//--------------------------------------------------------------------------fastcall TForm7::TForm7(TComponent* Owner)
: TForm(Owner)
{
}
39
//--------------------------------------------------------------------------UNIT 8.
//--------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop
#include "Unit8.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm" TForm8 *Form8;
//--------------------------------------------------------------------------fastcall TForm8::TForm8(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------void
{
//Botn cerrar
Close();
}
//--------------------------------------------------------------------------De esta manera es como se programa el Mtodo de Newton Raphson en
leguaje C++.
40
Una ecuacin de cuarto grado o ecuacin cuartica con una incgnita es una
ecuacin algebraica que se puede poner bajo la forma cannica: donde a, b, c,
d y e (siendo) son nmeros que pertenecen a un cuerpo, usualmente a los
reales o los complejos. Sea K un cuerpo, donde se pueden extraer races
cuadradas y cbicas (y por lo tanto tambin de cuarto orden, pues equivale a
extraer races cuadradas dos veces seguidas). En este cuerpo, es posible
factorizar por todo a, y la identidad siguiente es vlida:
En un cuerpo algebraicamente cerrado, se sabe que todo polinomio de grado 4
tiene cuatro races. Es el caso del cuerpo de los complejos, segn el Teorema
Fundamental del lgebra. El mtodo siguiente permite obtener las cuatro races
al mismo tiempo. Este mtodo es llamado "mtodo de Descartes", pues fue
dado por el matemtico francs Ren Descartes (1596-1650) en el ao de
1637 en su clebre libro "La Geometra". Aunque existan diferentes mtodos
para resolver las ecuaciones cuarticas, algunos son: mtodo de Ferrari, mtodo
de Descartes, mtodo de Euler, mtodo de Lagrange, mtodo de Alcal,
etctera.
41
1. SOLUCIN ALGEBRAICA
Tenemos una ecuacin de cuarto grado:
Ax + Bx + Cx + Dx + E=0
Ferrari menciona que el valor de A debe ser igual a 1, en caso contrario,
tendremos que dividir el polinomio entre A. Y quedar de la siguiente manera:
x + B/Ax + C/Ax + D/Ax + E/A=0
Tambin podemos escribir la ecuacin de esta forma:
x + ax + bx + cx+d=0
El mtodo de Ferrari nos proporciona una RESOLVENTE.
2. RESOLVENTE DE FERRARI
y -by + (ac-4ad)y +(4bd-ad-c )=0
Podemos cambiar la ecuacin por la siguiente forma:
x +ax +a x+ a=0
3. CUBICA DE FERRARI
En donde los valores tomados de a, b, c y d; son de la ecuacin de cuarto
grado
x + ax + bx + cx+d=0
4. Ya obtenida la cbica...
Para obtener las races de la ecuacin de cuarto grado. Usaremos el mtodo
de Cardano que consiste en calcular:
42
PROGRAMA:
44
Formulario 1:
Botn Entrar:
Botn Salir:
Lnea de Programacin:
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm" TForm1 *Form1;
//--------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner) { }
//--------------------------------------------------------------------------void __fastcall TForm1::Button1Click(TObject *Sender)
{
Form2->Show();
}
//--------------------------------------------------------------------------void __fastcall TForm1::Button2Click(TObject *Sender)
{
Close();
}
45
//---------------------------------------------------------------------------
Botn Races:
El botn lee los datos que ingresamos y realiza una serie de pasos para que
nos encuentre las races del polinomio que estamos buscando y nos ponga los
Botn Regresar:
46
Lnea de Programacin:
//--------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
#include <math.h>
#include <stdio.h>
double A,B,C,D,E,a,b,c,d,a1,a2,a3,q1,q2,q3,r1,r2,r3,r4,Q,R,S,s1,s2,s3,s4,s5;
double t1,t2,t3,t4,t5,T,y,e1,e2,e,f1,f2,f3,f,u1,u,v1,v,w1,w,z1,z,g1,g2,g3,g,i;
double x1,x2,x3,x4,y1,y2,y3,y4,Dis1,Dis2,Dis3,Dis4,Q1,R1,j,j2,o,o2,M,M1,M2,M3;
double M4,M5,M6,N,o1,o3;
TForm2 *Form2;
//--------------------------------------------------------------------------__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
47
if(A!=0)
{
a=B/A;
b=C/A;
c=D/A;
d=E/A;
a1=-b;
a2=(a*c)-(4*d);
a3=(4*b*d)-((a*a)*d)-(c*c);
q1=a1*a1;
q2=3*a2;
q3=q1-q2;
Q=q3/9;
r1=2*(a1*a1*a1);
r2=9*(a1*a2);
r3=27*a3;
r4=r1-r2+r3;
R=r4/54;
Q1=Q*Q*Q;
R1=R*R;
if(R1<Q1)
{
j=sqrt(Q1);
j2=R/j;
o=acos(j2);
o1=sqrt(Q);
o2=o/3;
o3=a1/3;
y=(-2*o1*cos(o2))-(o3);
48
e1=(a*a)/4;
e2=abs(e1-b+y);
e=sqrt(e2);
}
else
{
M1=abs(R);
M2=R1-Q1;
M3=sqrt(M2);
M4=M1+M3;
M5=1/3;
M6=pow(M4,M5);
M=(-1*(R))*M6;
if(M==0)
{
N=0;
}
else
{
N=Q/a1;
}
y=(M+N)-(a1/3);
e1=(a*a)/4;
e2=abs(e1-b+y);
e=sqrt(e2);
}
if(e!=0)
{
f1=a*y;
f2=2*c;
f3=f1-f2;
49
f=f3/e;
i=1;
u1=a/2;
u=u1-e;
v1=y/2;
v=v1-f;
w1=a/2;
w=w1+e;
z1=y/2;
z=z1+f;
Dis1=(u*u)-(4*i*v);
if(Dis1==0)
{
x1=-u/2*i;
x2=x1;
y1=0;
y2=0;
Edit6->Text=AnsiString(x1);
Edit7->Text=AnsiString(y1);
Edit8->Text=AnsiString(x2);
Edit9->Text=AnsiString(y2);
}
if(Dis1>0)
{
x1=-u/2*i+sqrt(Dis1)/(2*i);
x2=-u/2*i-sqrt(Dis1)/(2*i);
y1=0;
y2=0;
50
Edit6->Text=AnsiString(x1);
Edit7->Text=AnsiString(y1);
Edit8->Text=AnsiString(x2);
Edit9->Text=AnsiString(y2);
}
if(Dis1>0&&u!=0)
{
x1=-u/2*i;
x2=-u/2*i;
y1=sqrt(-Dis1)/(2*i);
y2=-sqrt(-Dis1)/(2*i);
Edit6->Text=AnsiString(x1);
Edit7->Text=AnsiString(y1);
Edit8->Text=AnsiString(x2);
Edit9->Text=AnsiString(y2);
}
if(Dis1<0&&u==0)
{
x1=0;
x2=x1;
y1=sqrt(-Dis1)/(2*i);
y2=-sqrt(-Dis1)/(2*i);
Edit6->Text=AnsiString(x1);
Edit7->Text=AnsiString(y1);
Edit8->Text=AnsiString(x2);
Edit9->Text=AnsiString(y2);
}
Dis2=(w*w)-(4*i*z);
if(Dis2==0)
{
x3=-w/2*i;
x4=x3;
y3=0;
y4=0;
51
Edit10->Text=AnsiString(x3);
Edit11->Text=AnsiString(y3);
Edit12->Text=AnsiString(x4);
Edit13->Text=AnsiString(y4);
}
if(Dis2>0)
{
x3=-w/2*i+sqrt(Dis2)/(2*i);
x4=-w/2*i-sqrt(Dis2)/(2*i);
y3=0;
y4=0;
Edit10->Text=AnsiString(x3);
Edit11->Text=AnsiString(y3);
Edit12->Text=AnsiString(x4);
Edit13->Text=AnsiString(y4);
}
if(Dis2>0&&w!=0)
{
x3=-w/2*i;
x4=-w/2*i;
y3=sqrt(-Dis2)/(2*i);
y4=-sqrt(-Dis2)/(2*i);
Edit10->Text=AnsiString(x3);
Edit11->Text=AnsiString(y3);
Edit12->Text=AnsiString(x4);
Edit13->Text=AnsiString(y4);
}
if(Dis2<0&&w==0)
{
x3=0;
x4=x1;
y3=sqrt(-Dis2)/(2*i);
y4=-sqrt(-Dis2)/(2*i);
Edit10->Text=AnsiString(x3);
52
Edit11->Text=AnsiString(y3);
Edit12->Text=AnsiString(x4);
Edit13->Text=AnsiString(y4);
}
}
if(e==0)
{
g1=y*y;
g2=g1/4;
g3=g2-d;
g=sqrt(g3);
i=1;
u1=a/2;
u=u1-e;
v1=y/2;
v=v1-g;
w1=a/2;
w=w1+e;
z1=y/2;
z=z1+g;
Dis3=(u*u)-(4*i*v);
if(Dis3==0)
{
x1=-u/2*i;
x2=x1;
y1=0;
y2=0;
Edit6->Text=AnsiString(x1);
Edit7->Text=AnsiString(y1);
Edit8->Text=AnsiString(x2);
53
Edit9->Text=AnsiString(y2);
}
if(Dis3>0)
{
x1=-u/2*i+sqrt(Dis3)/(2*i);
x2=-u/2*i-sqrt(Dis3)/(2*i);
y1=0;
y2=0;
Edit6->Text=AnsiString(x1);
Edit7->Text=AnsiString(y1);
Edit8->Text=AnsiString(x2);
Edit9->Text=AnsiString(y2);
}
if(Dis3>0&&u!=0)
{
x1=-u/2*i;
x2=-u/2*i;
y1=sqrt(-Dis3)/(2*i);
y2=-sqrt(-Dis3)/(2*i);
Edit6->Text=AnsiString(x1);
Edit7->Text=AnsiString(y1);
Edit8->Text=AnsiString(x2);
Edit9->Text=AnsiString(y2);
}
if(Dis3<0&&u==0)
{
x1=0;
x2=x1;
y1=sqrt(-Dis3)/(2*i);
y2=-sqrt(-Dis3)/(2*i);
Edit6->Text=AnsiString(x1);
Edit7->Text=AnsiString(y1);
Edit8->Text=AnsiString(x2);
Edit9->Text=AnsiString(y2);
54
}
Dis4=(w*w)-(4*i*z);
if(Dis4==0)
{
x3=-w/2*i;
x4=x3;
y3=0;
y4=0;
Edit10->Text=AnsiString(x3);
Edit11->Text=AnsiString(y3);
Edit12->Text=AnsiString(x4);
Edit13->Text=AnsiString(y4);
}
if(Dis4>0)
{
x3=-w/2*i+sqrt(Dis4)/(2*i);
x4=-w/2*i-sqrt(Dis4)/(2*i);
y3=0;
y4=0;
Edit10->Text=AnsiString(x3);
Edit11->Text=AnsiString(y3);
Edit12->Text=AnsiString(x4);
Edit13->Text=AnsiString(y4);
}
if(Dis4>0&&w!=0)
{
x3=-w/2*i;
x4=-w/2*i;
y3=sqrt(-Dis4)/(2*i);
y4=-sqrt(-Dis4)/(2*i);
Edit10->Text=AnsiString(x3);
Edit11->Text=AnsiString(y3);
Edit12->Text=AnsiString(x4);
Edit13->Text=AnsiString(y4);
55
}
if(Dis4<0&&w==0)
{
x3=0;
x4=x1;
y3=sqrt(-Dis4)/(2*i);
y4=-sqrt(-Dis4)/(2*i);
Edit10->Text=AnsiString(x3);
Edit11->Text=AnsiString(y3);
Edit12->Text=AnsiString(x4);
Edit13->Text=AnsiString(y4);
}
}
}
else
{
if(A==0)
{
Label13->Caption="No se puede realizar,es una ecuacin cbica!!";
}
}
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button2Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
56
4. Mtodo de Mller
Este es un mtodo para encontrar las races de ecuaciones polinomiales
con races mltiples, de la forma general:
f n ( x) a0 a1 x a2 x 2 ....... an x n
Ec.1
57
FIG 1
FIG. 2
Factorizando.
x=-4
Solucin 1
x=3
Solucin 2
58
NOTA!
El Teorema fundamental del lgebra nos dice que: El nmero de factores en
que se puede descomponer un polinomio es igual al grado del polinomio, es
decir: Todo polinomio de grado n tiene n races.
.Por tanto, en nuestra programacin, nicamente podremos encontrar
races de un polinomio hasta grado 4, esto quiere decir que el nmero de
races encontradas ser equivalente al nmero de grado del polinomio que
estemos evaluando.
RAICES REALES
Como las races de un polinomio hacen que este valga cero, en unplano
cartesiano esto lo identificamos como las intersecciones de la grfica del
polinomio con el eje de las X (abscisas). Esto es, los puntos en donde cruza la
grfica al eje horizontal tienen como abscisa la raz del polinomio graficado.
A continuacin presentamos algunas funciones con sus races, factores y
grficas:
Funcin
Races
Factorizacin
f(x)=
x2 + x
- 12
-4y3
f(x) = (x +
4) (x - 3)
f(x)= - 1, 2 y
3
x3 - 4
x2 + x
+6
Grfica
f(x) = (x +
1) (x - 2) (x
- 3)
59
f(x)= - 2, - 1, f(x) = (x +
1) (x + 2) (x
x4 - 5 1 y 2
- 1) (x - 2)
x2 + 4
f(x)= Cules
x3 + 4 son?
x2 + 3
x
f(x) =
Ejemplo:
Si la funcin con la que se trabaja es un cociente de polinomios, estos
debern ser reducidos a la mnima expresin con el objetivo de simplicar su
manejo. Dicha simplicacin se lleva a cabo eliminando factores comunes, y la
tarea de encontrar dichos factores est estrechamente ligada al clculo de las
races de los polinomios que aparecen en el numerador y el denominador.
Consideremos la funcin:
60
La cual coincide con f(x) excepto en x=-2. Las races involucradas en esta
funcin son:
Races de p(x) = 0, 3,
Races de q(x) = -1, 1.
f(x)
FIG. 3
RAICES IMAGINARIAS
61
y = xxx-4xx+5x
Las
races
de
la
funcin son:
X= 0, x=2+i, x=2-i
y = xxx-4xx+5x
y = x^(3)+x
y = x^(3)+x
Las races de la
funcin son:
X= 0, x=i, x=-i
, ( ) , , ( ) , ( ) .
0
1
2
f 2 ( x) a( x x2 ) b( x x2 ) c
2
FORMULAS
a utilizar
0 = 1
0
1 = 2
1
0 =
(1 )(0 )
1 0
1 =
(2 )(1 )
2 1
1 0
1 +0
= 1 +
1
= ( )
62
2 (0 ) = (0 2 )2 + (0 2 ) +
Ec. 2
2 (1 ) = (1 2 )2 + (1 2 ) +
Ec. 3
2 (2 ) = (2 2 )2 + (2 2 ) +
La ecuacin 4 genera que, ( ) =
Ec. 4
0 , 1 2 en f(x).Obtendremos:
(0 ) = ?
(1 ) = ?
(2 ) = ?
Obtendremos:
0 =?
1 =?
0 =?
1 =?
7. Ahora se encontrar a , (coeficientes de la parbola).
63
3 2 =
2 4
-Despejando-
3 = 2 +
2
2 4
Es decir, si
Se escoge
+ 4 4
Si no, se escoge:
2 4
3 2
3
repetir, esto con el fin de tener una mayor aproximacin a la raz X3, por lo
cual esto traer de que un valor es descartado.
DESVENTAJA
En el mtodo de Mller se escoge el signo que coincida con el
signo de b, esta eleccin proporciona como resultado el
denominador ms grande, lo que dar la raz estimada ms cercana a
x2. Una vez que se determin x3 el proceso se repite, esto trae de que
un valor es descartado.
ESTRATEGIAS COMNMENTE USADAS
64
DATO ADICIONAL
Si adems deseamos conocer los puntos en los que f (x) posee mximos y
mnimos locales, el procedimiento consiste en encontrar las races de f(X).
Si queremos ubicar los puntos de inexin de la funcin, es necesario ahora
encontrar las races de f(x).
0 = 4.5, 1 = 5.5, 2 = 5
= .
= .
0 = 5.5 4.5
1 = 5 5.5
=
= .
82.875 20.625
1
48 82.875
1 =
1
2
0 =
69.7562.25
1
2
= 15
=
= .
= .
1
+ 69.75
2
= .
Coeficientes de la parbola
65
3 = 5 +
2(48)
3.976487042 5
. 100 %
3.976487042
= 25.73912469 %
0 13 12 |
4
16
12 | 4
________________________|________
1 4
3
0 |
:
2 + 4 + 3
66
Obteniendo races de 2 + 4 + 3 :
4 42 4(1)(3)
1,2 =
2(1)
1 = 1,
2 = 3
FORMULA
1,2 =
2 4
2
67
PROGRAMACION
Programando Form 1
//--------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------void __fastcall TForm1::Button1Click(TObject *Sender)
{
Form2->Show();
Form1->Visible=false;
/*--------------ENTRAR--------------*/
}
//--------------------------------------------------------------------------void __fastcall TForm1::Button2Click(TObject *Sender)
{
Close();
/*--------------SALIR--------------*/
}
//--------------------------------------------------------------------------68
Programando Form 2
//--------------------------------------------------------------------------#include <vcl.h>
#include <math.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
#include "Unit3.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
double
a,b,c,d,e,x0,x1,x2,x3,j,z,D,A,B,C,fx0,fx1,fx2,h0,h1,d0,d1,w,ER=100,Er=100,o,p,q,r,s,u,v,rx1,lxl,m,l,R1,
R2;
TForm2 *Form2;
//--------------------------------------------------------------------------__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button1Click(TObject *Sender)
{
Label3->Caption="";
Label4->Caption="";
Label5->Caption="";
69
if(Er>=0.00000000000001){
a=Edit1->Text.ToDouble();
b=Edit2->Text.ToDouble();
c=Edit3->Text.ToDouble();
d=Edit4->Text.ToDouble();
e=Edit5->Text.ToDouble();
x0=Edit6->Text.ToDouble();
x1=Edit7->Text.ToDouble();
x2=Edit8->Text.ToDouble();
fx0=a*pow(x0,4)+b*pow(x0,3)+c*pow(x0,2)+d*x0+e;
fx1=a*pow(x1,4)+b*pow(x1,3)+c*pow(x1,2)+d*x1+e;
fx2=a*pow(x2,4)+b*pow(x2,3)+c*pow(x2,2)+d*x2+e;
h0=x1-x0;
h1=x2-x1;
if(h0==0|| h1==0||h1+h0==0)
{Label5->Caption="Prueba con otras aproximaciones";}
else{
/*--------------R1--------------*/
d0=(fx1-fx0)/h0;
d1=(fx2-fx1)/h1;
A=(d1-d0)/(h1+h0);
B=(A*h1)+d1;
C=fx2;
D=B*B-4*A*C;
if(D<0)
{Label3->Caption="posiblemente la funcin solo tenga raicesimaginarias,grafica y prueba nuevos
valores de x1,x2,x3!";}
else
{z=pow(D,0.5);
x3=x2-(2*C)/(B+z);
w=(x3-x2)/x3;
Edit8->Text=AnsiString(x3);
if(w<0)
{Er=(-w)*100;}
else
{Er=w*100;}
Edit6->Text=AnsiString(x1);
Edit7->Text=AnsiString(x2);
Edit9->Text=AnsiString(x3);
Edit15->Text=AnsiString(Er); }}}
else {Label4->Caption="EL ERROR es cero,Que mas quieres?!";}
}
//--------------------------------------------------------------------------70
fx2=b*pow(x2,3)+c*pow(x2,2)+d*x2+e;
h0=x1-x0;
h1=x2-x1;
if(h0==0|| h1==0||h1+h0==0)
{Label5->Caption="Prueba con otras aproximaciones";}
else{
d0=(fx1-fx0)/h0;
d1=(fx2-fx1)/h1;
A=(d1-d0)/(h1+h0);
B=(A*h1)+d1;
C=fx2;
D=B*B-4*A*C;
if(D<0)
{Label3->Caption="posiblemente la funcin solo tenga raicesimaginarias,grafica y prueba nuevos
valores de x1,x2,x3!";}
if(D>=0)
{z=pow(D,0.5);
x3=x2-(2*C)/(B+z);
w=(x3-x2)/x3;
Edit8->Text=AnsiString(x3);
w=(x3-x2)/x3;
if(w<0)
{ER=(-w)*100;}
else
{ER=w*100;}
Edit6->Text=AnsiString(x1);
Edit7->Text=AnsiString(x2);
Edit8->Text=AnsiString(x3);
71
Edit10->Text=AnsiString(x3);
Edit16->Text=AnsiString(ER); }}}
else {Label4->Caption="!EL ERROR YA ES CERO!";}}
//--------------------------------------------------------------------------void __fastcall TForm2::Button3Click(TObject *Sender)
{
Label3->Caption="";
Label4->Caption="";
Label5->Caption="";
a=Edit3->Text.ToDouble();
b=Edit4->Text.ToDouble();
c=Edit5->Text.ToDouble();
D=b*b-4*a*c;
if(D<0)
/*--------------R3--------------*/
{x1=(-b)/(2*a);
Edit11->Text=AnsiString(x1);
l=pow(-l*D,0.5)/(2*a);
Edit13->Text=AnsiString(l);}
else if(D>=0)
{r=pow(D,0.5);
x1=(-b+r)/(2*a);
Edit11->Text=AnsiString(x1);}
else{ D=-D;
r=pow(D,0.5);
rx1=(-b)/(2*a);
lxl=D/(2*a);
Edit11->Text=AnsiString(rx1);}}
//--------------------------------------------------------------------------void __fastcall TForm2::Button4Click(TObject *Sender)
{
Label3->Caption="";
Label4->Caption="";
Label5->Caption="";
a=Edit3->Text.ToDouble();
b=Edit4->Text.ToDouble();
c=Edit5->Text.ToDouble();
D=b*b-4*a*c;
if(D<0)
{x1=(-b)/(2*a);
Edit12->Text=AnsiString(x1);
l=pow(-l*D,0.5)/(2*a);
Edit14->Text=AnsiString(l);}
/*--------------R4--------------*/
else if(D>=0)
{r=pow(D,0.5);
x1=(-b-r)/(2*a);
Edit12->Text=AnsiString(x1);}
72
else{D=-D;
r=pow(D,0.5);
rx1=(-b)/(2*a);
lxl=D/(2*a);
Edit12->Text=AnsiString(rx1);}}
//--------------------------------------------------------------------------void __fastcall TForm2::Button5Click(TObject *Sender)
{
Label3->Caption="";
Label4->Caption="";
Label5->Caption="";
a=Edit1->Text.ToDouble();
b=Edit2->Text.ToDouble();
c=Edit3->Text.ToDouble();
d=Edit4->Text.ToDouble();
e=Edit5->Text.ToDouble();
R1=Edit9->Text.ToDouble();
o=a*R1;
p=b+o; /*--------------DEGRADAR CON R1--------------*/
q=p*R1;
r=c+q;
s=r*R1;
u=d+s;
v=u*R1;
w=e+v;
Edit1->Text="0";
Edit2->Text=AnsiString(a);
Edit3->Text=AnsiString(p);
Edit4->Text=AnsiString(r);
Edit5->Text=AnsiString(u);
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button6Click(TObject *Sender)
{
Label3->Caption="";
Label4->Caption="";
Label5->Caption="";
a=Edit2->Text.ToDouble();
b=Edit3->Text.ToDouble();
c=Edit4->Text.ToDouble();
d=Edit5->Text.ToDouble();
R2=Edit10->Text.ToDouble();
o=a*R2;
p=b+o;
q=p*R2;
r=c+q;
s=r*R2;
u=d+s;
Edit2->Text="0";
Edit3->Text=AnsiString(a);
73
Edit4->Text=AnsiString(p);
Edit5->Text=AnsiString(r);
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button7Click(TObject *Sender)
{
ER=100;
Er=100;
a=b=c=d=e=0;
Edit1->Text="";
Edit2->Text="";
Edit3->Text="";
Edit4->Text="";
Edit5->Text="";
Edit6->Text="";
Edit7->Text="";
/*--------------RESET--------------*/
Edit8->Text="";
Edit9->Text="";
Edit10->Text="";
Edit11->Text="";
Edit12->Text="";
Edit13->Text="0";
Edit14->Text="0";
Edit15->Text="";
Edit16->Text="";
Label3->Caption="";
Label4->Caption="";
Edit1->SetFocus();
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button8Click(TObject *Sender)
{
Form3->Show();
/*--------------GRAFICAR--------------*/
Close();
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button9Click(TObject *Sender)
{
Form1->Show();
/*--------------INICIO-------------*/
Close();
}
//---------------------------------------------------------------------------
Programando Form 3
74
//--------------------------------------------------------------------------#include <vcl.h>
#include <math.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
#include "Unit3.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
double a,b,c,d,e,x,y,av,pri,seg;
TForm3 *Form3;
//---------------------------------------------------------------------------
Canvas->PenPos=TPoint(560,310);
Canvas->LineTo(560,330);
Canvas->PenPos=TPoint(580,310);
Canvas->LineTo(580,330);
Canvas->PenPos=TPoint(600,310);
Canvas->LineTo(600,330);
Canvas->PenPos=TPoint(620,310);
Canvas->LineTo(620,330);
Canvas->PenPos=TPoint(640,310);
Canvas->LineTo(640,330);
Canvas->PenPos=TPoint(660,310);
Canvas->LineTo(660,330);
Canvas->PenPos=TPoint(680,310);
Canvas->LineTo(680,330);
Canvas->PenPos=TPoint(700,310);
Canvas->LineTo(700,330);
Canvas->PenPos=TPoint(460,310);
Canvas->LineTo(460,330);
Canvas->PenPos=TPoint(440,310);
Canvas->LineTo(440,330);
Canvas->PenPos=TPoint(420,310);
Canvas->LineTo(420,330);
Canvas->PenPos=TPoint(400,310);
Canvas->LineTo(400,330);
Canvas->PenPos=TPoint(380,310);
Canvas->LineTo(380,330);
Canvas->PenPos=TPoint(360,310);
Canvas->LineTo(360,330);
Canvas->PenPos=TPoint(340,310);
Canvas->LineTo(340,330);
Canvas->PenPos=TPoint(320,310);
Canvas->LineTo(320,330);
Canvas->PenPos=TPoint(300,310);
Canvas->LineTo(300,330);
Canvas->PenPos=TPoint(280,310);
Canvas->LineTo(280,330);
Canvas->PenPos=TPoint(470,120);
Canvas->LineTo(490,120);
Canvas->PenPos=TPoint(470,140);
Canvas->LineTo(490,140);
Canvas->PenPos=TPoint(470,300);
Canvas->LineTo(490,300);
Canvas->PenPos=TPoint(470,280);
Canvas->LineTo(490,280);
Canvas->PenPos=TPoint(470,260);
Canvas->LineTo(490,260);
Canvas->PenPos=TPoint(470,240);
Canvas->LineTo(490,240);
Canvas->PenPos=TPoint(470,220);
Canvas->LineTo(490,220);
Canvas->PenPos=TPoint(470,200);
Canvas->LineTo(490,200);
Canvas->PenPos=TPoint(470,180);
76
Canvas->LineTo(490,180);
Canvas->PenPos=TPoint(470,160);
Canvas->LineTo(490,160);
Label5->Caption="Y";
Label6->Caption="X";
Label7->Caption="2";
Label8->Caption="4";
Label9->Caption="6";
Label10->Caption="8";
Label11->Caption="10";
Label12->Caption="-2";
Label13->Caption="-4";
Label14->Caption="-6";
Label15->Caption="-8";
Label16->Caption="-10";
Label17->Caption="10";
a=Edit1->Text.ToDouble();
b=Edit2->Text.ToDouble();
c=Edit3->Text.ToDouble();
d=Edit4->Text.ToDouble();
e=Edit5->Text.ToDouble();
pri=Edit6->Text.ToDouble();
seg=Edit7->Text.ToDouble();
av=(seg-pri)/1000;
x=pri;
y=a*pow(x,4)+b*pow(x,3)+c*pow(x,2)+d*x+e;
Canvas->PenPos=TPoint(480+x*20,320-y*20);
for(pri;pri<=seg;pri=pri+av)
{x=pri;
y=a*pow(x,4)+b*pow(x,3)+c*pow(x,2)+d*x+e;
Canvas->LineTo(480+x*20,320-y*20);}
}
//--------------------------------------------------------------------------void __fastcall TForm3::Button3Click(TObject *Sender)
{
Form2->Show();/*--------------REGRESAR-------------*/
Close();
}
//--------------------------------------------------------------------------void __fastcall TForm3::Button4Click(TObject *Sender)
{
Form1->Close();/*--------------SALIR-------------*/
Close();
}
//--------------------------------------------------------------------------void __fastcall TForm3::Button2Click(TObject *Sender)
{
Edit1->Text="";
77
Edit2->Text="";
Edit3->Text="";
Edit4->Text="";/*--------------RESET-------------*/
Edit5->Text="";
Label5->Caption="";
Label6->Caption="";
Label7->Caption="";
Label8->Caption="";
Label9->Caption="";
Label10->Caption="";
Label11->Caption="";
Label12->Caption="";
Label13->Caption="";
Label14->Caption="";
Label15->Caption="";
Label16->Caption="";
Label17->Caption="";
Edit1->SetFocus();}
//---------------------------------------------------------------------------
78
79
80
81
PROGRAMACIN
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
82
83
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include "Unit3.h"
#include "Unit4.h"
#include "Unit5.h"
#include "Unit6.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
84
Form5->Show();
}
//---------------------------------------------------------------------------
INTERFAZ DE 2 INCGNITAS
Se compone de: 36-Label 3-Button 6-Edit 1-Picture
Buttons:
1) Solucin: Inicia el proceso de solucin del sistema de ecuaciones
lineales.
2) Borrar todo: Borra el proceso de triangulacin y la solucin del sistema
as como la informacin en los Edit.
3) Salir: Cierra la Interfaz de 2 Incgnitas.
PROGRAMACIN
//---------------------------------------------------------------------------
86
#include <vcl.h>
#pragma hdrstop
#include "Unit3.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
//--------------------------------------------------------------------------__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
{
x1= Edit1->Text.ToDouble();
y1= Edit2->Text.ToDouble();
z1= Edit3->Text.ToDouble();
x2= Edit4->Text.ToDouble();
y2= Edit5->Text.ToDouble();
z2= Edit6->Text.ToDouble();
87
z1= z1/x1;
y1= y1/x1;
x1= x1/x1;
Label7->Caption=FormatFloat("0.###",x1);
Label8->Caption=FormatFloat("0.###",y1);
Label9->Caption=FormatFloat("0.###",z1);
z2= z2/x2;
y2= y2/x2;
x2= x2/x2;
Label10->Caption=FormatFloat("0.###",x2);
Label11->Caption=FormatFloat("0.###",y2);
Label12->Caption=FormatFloat("0.###",z2);
x2=x1-x2;
y2=y1-y2;
z2=z1-z2;
if(y2<0)
{
y2=-y2;
z2=-z2;
}
z2=z2/y2;
y2=y2/y2;
88
Label13->Caption=FormatFloat("0.###",x1);
Label14->Caption=FormatFloat("0.###",y1);
Label15->Caption=FormatFloat("0.###",z1);
Label16->Caption=FormatFloat("0.###",x2);
Label17->Caption=FormatFloat("0.###",y2);
Label18->Caption=FormatFloat("0.###",z2);
y3=y1*y2;
z3=y1*z2;
y1=y1-y3;
z1=z1-z3;
Label19->Caption=FormatFloat("0.###",x1);
Label20->Caption=FormatFloat("0.###",y1);
Label21->Caption=FormatFloat("0.###",z1);
Label22->Caption=FormatFloat("0.###",x2);
Label23->Caption=FormatFloat("0.###",y2);
Label24->Caption=FormatFloat("0.###",z2);
Label25->Caption="[";
Label26->Caption="]";
Label27->Caption="[";
Label28->Caption="]";
89
Label29->Caption="[";
Label30->Caption="]";
Label31->Caption="x1 -->";
Label32->Caption="x2 -->";
Label33->Caption="RESULTADO:";
Label35->Caption=FormatFloat("0.###",z1);
Label36->Caption=FormatFloat("0.###",z2);
}
//--------------------------------------------------------------------------void __fastcall TForm3::Button1Click(TObject *Sender)
{
Edit1->Text="";
Edit2->Text="";
Edit3->Text="";
Edit4->Text="";
Edit5->Text="";
Edit6->Text="";
Edit1->SetFocus();
Label7->Caption="";
Label8->Caption="";
Label9->Caption="";
Label10->Caption="";
90
Label11->Caption="";
Label12->Caption="";
Label13->Caption="";
Label14->Caption="";
Label15->Caption="";
Label16->Caption="";
Label17->Caption="";
Label18->Caption="";
Label19->Caption="";
Label20->Caption="";
Label21->Caption="";
Label22->Caption="";
Label23->Caption="";
Label24->Caption="";
Label25->Caption="";
Label26->Caption="";
Label27->Caption="";
Label28->Caption="";
Label29->Caption="";
Label30->Caption="";
Label31->Caption="";
Label32->Caption="";
Label33->Caption="";
Label35->Caption="";
Label36->Caption="";
}
//--------------------------------------------------------------------------void __fastcall TForm3::Button3Click(TObject *Sender)
91
{
Close();
}
//--------------------------------------------------------------------------INTERFAZ DE 3 INCGNITAS
#include <vcl.h>
#pragma hdrstop
#include "Unit4.h"
//--------------------------------------------------------------------------92
#pragma package(smart_init)
#pragma resource "*.dfm"
double x1, y1, z1, a, x2, y2, z2, b, x3, y3, z3, c, w;
TForm4 *Form4;
//--------------------------------------------------------------------------__fastcall TForm4::TForm4(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------void __fastcall TForm4::Button2Click(TObject *Sender)
{
x1= Edit1->Text.ToDouble();
y1= Edit2->Text.ToDouble();
z1= Edit3->Text.ToDouble();
a= Edit4->Text.ToDouble();
x2= Edit5->Text.ToDouble();
y2= Edit6->Text.ToDouble();
z2= Edit7->Text.ToDouble();
b= Edit8->Text.ToDouble();
x3= Edit9->Text.ToDouble();
y3= Edit10->Text.ToDouble();
z3= Edit11->Text.ToDouble();
c= Edit12->Text.ToDouble();
93
a=a/x1;
z1=z1/x1;
y1=y1/x1;
x1=x1/x1;
if(x2==0)
{
b=b/y2;
z2=z2/y2;
y2=y2/y2;
}
else
{
b=b/x2;
z2=z2/x2;
y2=y2/x2;
x2=x2/x2;
if(x3==0)
{
c=c/y3;
z3=z3/y3;
y3=y3/y3;
}
else
94
{
c=c/x3;
z3=z3/x3;
y3=y3/x3;
x3=x3/x3;
}
Label13->Caption=FormatFloat("0.###",x1);
Label14->Caption=FormatFloat("0.###",y1);
Label15->Caption=FormatFloat("0.###",z1);
Label16->Caption=FormatFloat("0.###",a);
Label17->Caption=FormatFloat("0.###",x2);
Label18->Caption=FormatFloat("0.###",y2);
Label19->Caption=FormatFloat("0.###",z2);
Label20->Caption=FormatFloat("0.###",b);
Label21->Caption=FormatFloat("0.###",x3);
Label22->Caption=FormatFloat("0.###",y3);
Label23->Caption=FormatFloat("0.###",z3);
Label24->Caption=FormatFloat("0.###",c);
if(x2==0)
{
y2=y2;
z2=z2;
b=b;
}
95
else
{
x2=x1-x2;
y2=y1-y2;
z2=z1-z2;
b=a-b;
}
if(y2==0)
{
b=b/z2;
z2=z2/z2;
}
else
{
b=b/y2;
z2=z2/y2;
y2=y2/y2;
}
if(x3==0)
{
y3=y3;
z3=z3;
c=c;
}
96
else
{
x3=x1-x3;
y3=y1-y3;
z3=z1-z3;
c=a-c;
}
if(y3==0)
{
c=c/z3;
z3=z3/z3;
}
else
{
c=c/y3;
z3=z3/y3;
y3=y3/y3;
Label25->Caption=FormatFloat("0.###",x1);
Label26->Caption=FormatFloat("0.###",y1);
Label27->Caption=FormatFloat("0.###",z1);
Label28->Caption=FormatFloat("0.###",a);
Label29->Caption=FormatFloat("0.###",x2);
Label30->Caption=FormatFloat("0.###",y2);
97
Label31->Caption=FormatFloat("0.###",y2);
Label32->Caption=FormatFloat("0.###",b);
Label33->Caption=FormatFloat("0.###",x3);
Label34->Caption=FormatFloat("0.###",y3);
Label35->Caption=FormatFloat("0.###",z3);
Label36->Caption=FormatFloat("0.###",c);
y3=y2-y3;
z3=z2-z3;
c=b-c;
c=c/z3;
z3=z3/z3;
Label37->Caption=FormatFloat("0.###",x1);
Label38->Caption=FormatFloat("0.###",y1);
Label39->Caption=FormatFloat("0.###",z1);
Label40->Caption=FormatFloat("0.###",a);
Label41->Caption=FormatFloat("0.###",x2);
Label42->Caption=FormatFloat("0.###",y2);
Label43->Caption=FormatFloat("0.###",z2);
Label44->Caption=FormatFloat("0.###",b);
Label45->Caption=FormatFloat("0.###",x3);
Label46->Caption=FormatFloat("0.###",y3);
Label47->Caption=FormatFloat("0.###",z3);
98
Label48->Caption=FormatFloat("0.###",c);
b=b-(z2*c);
a=a-(y1*b)-(z1*c);
Label49->Caption=FormatFloat("0.###",a);
Label50->Caption=FormatFloat("0.###",b);
Label51->Caption=FormatFloat("0.###",c);
Label54->Caption="x1 ->";
Label55->Caption="x2 ->";
Label56->Caption="x3 ->";
Label57->Caption="[";
Label58->Caption="]";
Label59->Caption="[";
Label60->Caption="]";
Label61->Caption="[";
Label62->Caption="]";
Label63->Caption="RESULTADO:";
}
//---------------------------------------------------------------------------
Label13->Caption="";
Label14->Caption="";
Label15->Caption="";
Label16->Caption="";
Label17->Caption="";
Label18->Caption="";
Label19->Caption="";
Label20->Caption="";
Label21->Caption="";
Label22->Caption="";
Label23->Caption="";
100
Label24->Caption="";
Label25->Caption="";
Label26->Caption="";
Label27->Caption="";
Label28->Caption="";
Label29->Caption="";
Label30->Caption="";
Label31->Caption="";
Label32->Caption="";
Label33->Caption="";
Label34->Caption="";
Label35->Caption="";
Label36->Caption="";
Label37->Caption="";
Label38->Caption="";
Label39->Caption="";
Label40->Caption="";
Label41->Caption="";
Label42->Caption="";
Label43->Caption="";
Label44->Caption="";
Label45->Caption="";
Label46->Caption="";
Label47->Caption="";
Label48->Caption="";
Label49->Caption="";
Label50->Caption="";
Label51->Caption="";
101
Label54->Caption="";
Label55->Caption="";
Label56->Caption="";
Label57->Caption="";
Label58->Caption="";
Label59->Caption="";
Label60->Caption="";
Label61->Caption="";
Label62->Caption="";
Label63->Caption="";
}
//--------------------------------------------------------------------------INTERFAZ DE 4 INCGNITAS
#include <vcl.h>
#pragma hdrstop
#include "Unit5.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
double a, b, c, d, x1, y1, z1, w1, x2, y2, z2, w2, x3, y3, z3, w3, x4, y4, z4, w4;
TForm5 *Form5;
//--------------------------------------------------------------------------__fastcall TForm5::TForm5(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
x1= Edit1->Text.ToDouble();
y1= Edit2->Text.ToDouble();
z1= Edit3->Text.ToDouble();
103
w1= Edit4->Text.ToDouble();
a= Edit5->Text.ToDouble();
x2= Edit6->Text.ToDouble();
y2= Edit7->Text.ToDouble();
z2= Edit8->Text.ToDouble();
w2= Edit9->Text.ToDouble();
b= Edit10->Text.ToDouble();
x3= Edit11->Text.ToDouble();
y3= Edit12->Text.ToDouble();
z3= Edit13->Text.ToDouble();
w3= Edit14->Text.ToDouble();
c= Edit15->Text.ToDouble();
x4= Edit16->Text.ToDouble();
y4= Edit17->Text.ToDouble();
z4= Edit18->Text.ToDouble();
w4= Edit19->Text.ToDouble();
d= Edit20->Text.ToDouble();
a=a/x1;
w1=w1/x1;
z1=z1/x1;
y1=y1/x1;
x1=x1/x1;
if(x2==0)
104
{
b=b/y2;
w2=w2/y2;
z2=z2/y2;
y2=y2/y2;
}
else
{
b=b/x2;
w2=w2/x2;
z2=z2/x2;
y2=y2/x2;
x2=x2/x2;
}
if(x3==0)
{
if(y3==0)
{
c=c/z3;
w3=w3/z3;
z3=z3/z3;
}
else
{
c=c/y3;
w3=w3/y3;
z3=z3/y3;
105
y3=y3/y3;
}
}
else
{
c=c/x3;
w3=w3/x3;
z3=z3/x3;
y3=y3/x3;
x3=x3/x3;
}
if(x4==0)
{
if(y4==0)
{
if(z4==0)
{
d=d/w4;
w4=w4/w4;
}
else
{
d=d/z4;
w4=w4/z4;
z4=z4/z4;
}
}
else
106
{
d=d/y4;
w4=w4/y4;
z4=z4/y4;
y4=y4/y4;
}
}
else
{
d=d/x4;
w4=w4/x4;
z4=z4/x4;
y4=y4/x4;
x4=x4/x4;
}
Label18->Caption=FormatFloat("0.###",x1);
Label19->Caption=FormatFloat("0.###",y1);
Label20->Caption=FormatFloat("0.###",z1);
Label21->Caption=FormatFloat("0.###",w1);
Label22->Caption=FormatFloat("0.###",a);
Label23->Caption=FormatFloat("0.###",x2);
Label24->Caption=FormatFloat("0.###",y2);
Label25->Caption=FormatFloat("0.###",z2);
Label26->Caption=FormatFloat("0.###",w2);
Label27->Caption=FormatFloat("0.###",b);
107
Label28->Caption=FormatFloat("0.###",x3);
Label29->Caption=FormatFloat("0.###",y3);
Label30->Caption=FormatFloat("0.###",z3);
Label31->Caption=FormatFloat("0.###",w3);
Label32->Caption=FormatFloat("0.###",c);
Label33->Caption=FormatFloat("0.###",x4);
Label34->Caption=FormatFloat("0.###",y4);
Label35->Caption=FormatFloat("0.###",z4);
Label36->Caption=FormatFloat("0.###",w4);
Label37->Caption=FormatFloat("0.###",d);
if(x2==0)
{
x2=x2;
y2=y2;
z2=z2;
w2=w2;
b=b;
}
else
{
x2=x1-x2;
y2=y1-y2;
z2=z1-z2;
w2=w1-w2;
b=a-b;
108
b=b/y2;
w2=w2/y2;
z2=z2/y2;
y2=y2/y2;
}
if(x3==0)
{
x3=x3;
y3=y3;
z3=z3;
w3=w3;
c=c;
}
else
{
x3=x1-x3;
y3=y1-y3;
z3=z1-z3;
w3=w1-w3;
c=a-c;
if(y3==0)
{
c=c/z3;
w3=w3/z3;
z3=z3/z3;
109
}
else
{
c=c/y3;
w3=w3/y3;
z3=z3/y3;
y3=y3/y3;
}
}
if(x4==0)
{
x4=x4;
y4=y4;
z4=z4;
w4=w4;
d=d;
}
else
{
x4=x1-x4;
y4=y1-y4;
z4=z1-z4;
w4=w1-w4;
d=a-d;
if(y4==0)
{
110
d=d/z4;
w4=w4/z4;
z4=z4/z4;
}
else
{
d=d/y4;
w4=w4/y4;
z4=z4/y4;
y4=y4/y4;
}
}
Label38->Caption=FormatFloat("0.###",x1);
Label39->Caption=FormatFloat("0.###",y1);
Label40->Caption=FormatFloat("0.###",z1);
Label41->Caption=FormatFloat("0.###",w1);
Label42->Caption=FormatFloat("0.###",a);
Label43->Caption=FormatFloat("0.###",x2);
Label44->Caption=FormatFloat("0.###",y2);
Label45->Caption=FormatFloat("0.###",z2);
Label46->Caption=FormatFloat("0.###",w2);
Label47->Caption=FormatFloat("0.###",b);
Label48->Caption=FormatFloat("0.###",x3);
Label49->Caption=FormatFloat("0.###",y3);
Label50->Caption=FormatFloat("0.###",z3);
111
Label51->Caption=FormatFloat("0.###",w3);
Label52->Caption=FormatFloat("0.###",c);
Label54->Caption=FormatFloat("0.###",x4);
Label55->Caption=FormatFloat("0.###",y4);
Label56->Caption=FormatFloat("0.###",z4);
Label57->Caption=FormatFloat("0.###",w4);
Label58->Caption=FormatFloat("0.###",d);
if(y3==0)
{
x3=x3;
y3=y3;
z3=z3;
w3=w3;
c=c;
}
else
{
x3=x3;
y3=y2-y3;
z3=z2-z3;
w3=w2-w3;
c=b-c;
c=c/z3;
w3=w3/z3;
z3=z3/z3;
112
}
if(y4==0)
{
x4=x4;
y4=y4;
z4=z4;
w4=w4;
d=d;
}
else
{
x4=x4;
y4=y2-y4;
z4=z2-z4;
w4=w2-w4;
d=b-d;
d=d/z4;
w4=w4/z4;
z4=z4/z4;
}
Label59->Caption=FormatFloat("0.###",x1);
Label60->Caption=FormatFloat("0.###",y1);
Label61->Caption=FormatFloat("0.###",z1);
Label62->Caption=FormatFloat("0.###",w1);
Label63->Caption=FormatFloat("0.###",a);
113
Label66->Caption=FormatFloat("0.###",x2);
Label67->Caption=FormatFloat("0.###",y2);
Label68->Caption=FormatFloat("0.###",z2);
Label69->Caption=FormatFloat("0.###",w2);
Label70->Caption=FormatFloat("0.###",b);
Label71->Caption=FormatFloat("0.###",x3);
Label72->Caption=FormatFloat("0.###",y3);
Label73->Caption=FormatFloat("0.###",z3);
Label74->Caption=FormatFloat("0.###",w3);
Label75->Caption=FormatFloat("0.###",c);
Label76->Caption=FormatFloat("0.###",x4);
Label77->Caption=FormatFloat("0.###",y4);
Label78->Caption=FormatFloat("0.###",z4);
Label79->Caption=FormatFloat("0.###",w4);
Label80->Caption=FormatFloat("0.###",d);
if(z4==0)
{
x4=x4;
y4=y4;
z4=z4;
w4=w4;
d=d;
}
else
{
114
x4=x4;
y4=y3;
z4=z3-z4;
w4=w3-w4;
d=c-d;
d=d/w4;
w4=w4/w4;
}
Label81->Caption=FormatFloat("0.###",x1);
Label82->Caption=FormatFloat("0.###",y1);
Label83->Caption=FormatFloat("0.###",z1);
Label84->Caption=FormatFloat("0.###",w1);
Label85->Caption=FormatFloat("0.###",a);
Label86->Caption=FormatFloat("0.###",x2);
Label87->Caption=FormatFloat("0.###",y2);
Label88->Caption=FormatFloat("0.###",z2);
Label89->Caption=FormatFloat("0.###",w2);
Label90->Caption=FormatFloat("0.###",b);
Label91->Caption=FormatFloat("0.###",x3);
Label92->Caption=FormatFloat("0.###",y3);
Label93->Caption=FormatFloat("0.###",z3);
Label94->Caption=FormatFloat("0.###",w3);
Label95->Caption=FormatFloat("0.###",c);
Label96->Caption=FormatFloat("0.###",x4);
115
Label97->Caption=FormatFloat("0.###",y4);
Label98->Caption=FormatFloat("0.###",z4);
Label99->Caption=FormatFloat("0.###",w4);
Label100->Caption=FormatFloat("0.###",d);
w4=d;
z3=c-(d*w3);
y2=b-(d*w2)-(z3*z2);
x1=a-(d*w1)-(z3*z1)-(y2*y1);
Label105->Caption=FormatFloat("0.###",x1);
Label106->Caption=FormatFloat("0.###",y2);
Label107->Caption=FormatFloat("0.###",z3);
Label108->Caption=FormatFloat("0.###",w4);
Label101->Caption="x1-->";
Label102->Caption="y1-->";
Label103->Caption="z1-->";
Label104->Caption="w1-->";
Label109->Caption="[";
Label113->Caption="]";
Label110->Caption="[";
Label114->Caption="]";
Label111->Caption="[";
Label115->Caption="]";
116
Label112->Caption="[";
Label116->Caption="]";
Label117->Caption="RESULTADO:";
}
//--------------------------------------------------------------------------void __fastcall TForm5::Button1Click(TObject *Sender)
{
Edit1->Text="";
Edit2->Text="";
Edit3->Text="";
Edit4->Text="";
Edit5->Text="";
Edit6->Text="";
Edit7->Text="";
Edit8->Text="";
Edit9->Text="";
Edit10->Text="";
Edit11->Text="";
Edit12->Text="";
Edit13->Text="";
Edit14->Text="";
Edit15->Text="";
Edit16->Text="";
Edit17->Text="";
Edit18->Text="";
Edit19->Text="";
117
Edit20->Text="";
Edit1->SetFocus();
Label18->Caption="";
Label19->Caption="";
Label20->Caption="";
Label21->Caption="";
Label22->Caption="";
Label23->Caption="";
Label24->Caption="";
Label25->Caption="";
Label26->Caption="";
Label27->Caption="";
Label28->Caption="";
Label29->Caption="";
Label30->Caption="";
Label31->Caption="";
Label32->Caption="";
Label33->Caption="";
Label34->Caption="";
Label35->Caption="";
Label36->Caption="";
Label37->Caption="";
Label38->Caption="";
Label39->Caption="";
Label40->Caption="";
Label41->Caption="";
118
Label42->Caption="";
Label43->Caption="";
Label44->Caption="";
Label45->Caption="";
Label46->Caption="";
Label47->Caption="";
Label48->Caption="";
Label49->Caption="";
Label50->Caption="";
Label51->Caption="";
Label52->Caption="";
Label54->Caption="";
Label55->Caption="";
Label56->Caption="";
Label57->Caption="";
Label58->Caption="";
Label59->Caption="";
Label60->Caption="";
Label61->Caption="";
Label62->Caption="";
Label63->Caption="";
Label66->Caption="";
Label67->Caption="";
Label68->Caption="";
Label69->Caption="";
Label70->Caption="";
Label71->Caption="";
Label72->Caption="";
119
Label73->Caption="";
Label74->Caption="";
Label75->Caption="";
Label76->Caption="";
Label77->Caption="";
Label78->Caption="";
Label79->Caption="";
Label80->Caption="";
Label81->Caption="";
Label82->Caption="";
Label83->Caption="";
Label84->Caption="";
Label85->Caption="";
Label86->Caption="";
Label87->Caption="";
Label88->Caption="";
Label89->Caption="";
Label90->Caption="";
Label91->Caption="";
Label92->Caption="";
Label93->Caption="";
Label94->Caption="";
Label95->Caption="";
Label96->Caption="";
Label97->Caption="";
Label98->Caption="";
Label99->Caption="";
Label100->Caption="";
120
Label101->Caption="";
Label102->Caption="";
Label103->Caption="";
Label104->Caption="";
Label105->Caption="";
Label106->Caption="";
Label107->Caption="";
Label108->Caption="";
Label109->Caption="";
Label110->Caption="";
Label111->Caption="";
Label112->Caption="";
Label113->Caption="";
Label114->Caption="";
Label115->Caption="";
Label116->Caption="";
Label117->Caption="";
}
//---------------------------------------------------------------------------
INTERFAZ DE 5 INCGNITAS
121
#include <vcl.h>
#pragma hdrstop
#include "Unit6.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
double a, b, c, d, e, x1, y1, z1, w1, u1, x2, y2, z2, w2, u2, x3, y3, z3, w3, u3, x4,
y4, z4, w4, u4, x5, y5, z5, w5, u5;
122
TForm6 *Form6;
//--------------------------------------------------------------------------__fastcall TForm6::TForm6(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
x2= Edit7->Text.ToDouble();
y2= Edit8->Text.ToDouble();
z2= Edit9->Text.ToDouble();
w2= Edit10->Text.ToDouble();
u2= Edit11->Text.ToDouble();
b= Edit12->Text.ToDouble();
x3= Edit13->Text.ToDouble();
y3= Edit14->Text.ToDouble();
z3= Edit15->Text.ToDouble();
123
w3= Edit16->Text.ToDouble();
u3= Edit17->Text.ToDouble();
c= Edit18->Text.ToDouble();
x4= Edit19->Text.ToDouble();
y4= Edit20->Text.ToDouble();
z4= Edit21->Text.ToDouble();
w4= Edit22->Text.ToDouble();
u4= Edit23->Text.ToDouble();
d= Edit24->Text.ToDouble();
x5= Edit25->Text.ToDouble();
y5= Edit26->Text.ToDouble();
z5= Edit27->Text.ToDouble();
w5= Edit28->Text.ToDouble();
u5= Edit29->Text.ToDouble();
e= Edit30->Text.ToDouble();
a=a/x1;
u1=u1/x1;
w1=w1/x1;
z1=z1/x1;
y1=y1/x1;
x1=x1/x1;
if(x2==0)
{
b=b/y2;
124
u2=u2/y2;
w2=w2/y2;
z2=z2/y2;
y2=y2/y2;
}
else
{
b=b/x1;
u2=u2/x2;
w2=w2/x2;
z2=z2/x2;
y2=y2/x2;
x2=x2/x2;
}
if(x3==0)
{
if(y3==0)
{
c=c/z3;
u3=u3/z3;
w3=w3/z3;
z3=z3/z3;
}
else
{
c=c/y3;
u3=u3/y3;
w3=w3/y3;
125
z3=z3/y3;
y3=y3/y3;
}
}
else
{
c=c/x3;
u3=u3/x3;
w3=w3/x3;
z3=z3/x3;
y3=y3/x3;
x3=x3/x3;
}
if(x4==0)
{
if(y4==0)
{
if(z4==0)
{
d=d/w4;
u4=u4/w4;
w4=w4/w4;
}
else
{
d=d/z4;
u4=u4/z4;
w4=w4/z4;
126
z4=z4/z4;
}
}
else
{
d=d/y4;
u4=u4/y4;
w4=w4/y4;
z4=z4/y4;
y4=y4/y4;
}
}
else
{
d=d/x4;
u4=u4/x4;
w4=w4/x4;
z4=z4/x4;
y4=y4/x4;
x4=x4/x4;
}
if(x5==0)
{
if(y5==0)
{
if(z5==0)
{
if(w5==0)
127
{
e=e/u5;
u5=u5/u5;
}
else
{
e=e/w5;
u5=u5/w5;
w5=w5/w5;
}
}
else
{
e=e/z5;
u5=u5/z5;
w5=w5/z5;
z5=z5/z5;
}
}
else
{
e=e/y5;
u5=u5/y5;
w5=w5/y5;
z5=z5/y5;
y5=y5/y5;
}
}
128
else
{
e=e/x5;
u5=u5/x5;
w5=w5/x5;
z5=z5/x5;
y5=y5/x5;
x5=x5/x5;
}
Label28->Caption=FormatFloat("0.###",x1);
Label29->Caption=FormatFloat("0.###",y1);
Label30->Caption=FormatFloat("0.###",z1);
Label31->Caption=FormatFloat("0.###",w1);
Label32->Caption=FormatFloat("0.###",u1);
Label33->Caption=FormatFloat("0.###",a);
Label34->Caption=FormatFloat("0.###",x2);
Label35->Caption=FormatFloat("0.###",y2);
Label36->Caption=FormatFloat("0.###",z2);
Label37->Caption=FormatFloat("0.###",w2);
Label38->Caption=FormatFloat("0.###",u2);
Label39->Caption=FormatFloat("0.###",b);
Label40->Caption=FormatFloat("0.###",x3);
Label41->Caption=FormatFloat("0.###",y3);
Label42->Caption=FormatFloat("0.###",z3);
Label43->Caption=FormatFloat("0.###",w3);
Label44->Caption=FormatFloat("0.###",u3);
129
Label45->Caption=FormatFloat("0.###",c);
Label46->Caption=FormatFloat("0.###",x4);
Label47->Caption=FormatFloat("0.###",y4);
Label48->Caption=FormatFloat("0.###",z4);
Label49->Caption=FormatFloat("0.###",w4);
Label50->Caption=FormatFloat("0.###",u4);
Label51->Caption=FormatFloat("0.###",d);
Label52->Caption=FormatFloat("0.###",x5);
Label53->Caption=FormatFloat("0.###",y5);
Label54->Caption=FormatFloat("0.###",z5);
Label55->Caption=FormatFloat("0.###",w5);
Label56->Caption=FormatFloat("0.###",u5);
Label57->Caption=FormatFloat("0.###",e);
if(x2==0)
{
x2=x2;
y2=y2;
z2=z2;
w2=w2;
u2=u2;
b=b;
}
else
{
x2=x1-x2;
130
y2=y1-y2;
z2=z1-z2;
w2=w1-w2;
u2=u1-u2;
b=a-b;
b=b/y2;
u2=u2/y2;
w2=w2/y2;
z2=z2/y2;
y2=y2/y2;
}
if(x3==0)
{
x3=x3;
y3=y3;
z3=z3;
w3=w3;
u3=u3;
c=c;
}
else
{
x3=x1-x3;
y3=y1-y3;
z3=z1-z3;
w3=w1-w3;
131
u3=u1-u3;
c=a-c;
if(y3==0)
{
c=c/z3;
u3=u3/z3;
w3=w3/z3;
z3=z3/z3;
}
else
{
c=c/y3;
u3=u3/y3;
w3=w3/y3;
z3=z3/y3;
y3=y3/y3;
}
}
if(x4==0)
{
x4=x4;
y4=y4;
z4=z4;
w4=w4;
u4=u4;
d=d;
}
132
else
{
x4=x1-x4;
y4=y1-y4;
z4=z1-z4;
w4=w1-w4;
u4=u1-u4;
d=a-d;
if(y4==0)
{
if(z4==0)
{
d=d/w4;
u4=u4/w4;
w4=w4/w4;
}
else
{
d=d/z4;
u4=u4/z4;
w4=w4/z4;
z4=z4/z4;
}
}
else
{
d=d/y4;
133
u4=u4/y4;
w4=w4/y4;
z4=z4/y4;
y4=y4/y4;
}
}
if(x5==0)
{
x5=x5;
y5=y5;
z5=z5;
w5=w5;
u5=u5;
e=e;
}
else
{
x5=x1-x5;
y5=y1-y5;
z5=z1-z5;
w5=w1-w5;
u5=u1-u5;
e=a-e;
if(y5==0)
{
if(z5==0)
{
134
if(w5==0)
{
e=e/w5;
u5=u5/u5;
}
else
{
e=e/w5;
u5=u5/w5;
w5=w5/w5;
}
}
else
{
e=e/z5;
u5=u5/z5;
w5=w5/z5;
z5=z5/z5;
}
}
else
{
e=e/y5;
u5=u5/y5;
w5=w5/y5;
z5=z5/y5;
y5=y5/y5;
}
135
Label58->Caption=FormatFloat("0.###",x1);
Label59->Caption=FormatFloat("0.###",y1);
Label60->Caption=FormatFloat("0.###",z1);
Label61->Caption=FormatFloat("0.###",w1);
Label62->Caption=FormatFloat("0.###",u1);
Label63->Caption=FormatFloat("0.###",a);
Label64->Caption=FormatFloat("0.###",x2);
Label65->Caption=FormatFloat("0.###",y2);
Label66->Caption=FormatFloat("0.###",z2);
Label67->Caption=FormatFloat("0.###",w2);
Label68->Caption=FormatFloat("0.###",u2);
Label69->Caption=FormatFloat("0.###",b);
Label70->Caption=FormatFloat("0.###",x3);
Label71->Caption=FormatFloat("0.###",y3);
Label72->Caption=FormatFloat("0.###",z3);
Label73->Caption=FormatFloat("0.###",w3);
Label74->Caption=FormatFloat("0.###",u3);
Label75->Caption=FormatFloat("0.###",c);
Label76->Caption=FormatFloat("0.###",x4);
Label77->Caption=FormatFloat("0.###",y4);
Label78->Caption=FormatFloat("0.###",z4);
Label79->Caption=FormatFloat("0.###",w4);
Label80->Caption=FormatFloat("0.###",u4);
136
Label81->Caption=FormatFloat("0.###",d);
Label82->Caption=FormatFloat("0.###",x5);
Label83->Caption=FormatFloat("0.###",y5);
Label84->Caption=FormatFloat("0.###",z5);
Label85->Caption=FormatFloat("0.###",w5);
Label86->Caption=FormatFloat("0.###",u5);
Label87->Caption=FormatFloat("0.###",e);
if(y3==0)
{
x3=x3;
y3=y3;
z3=z3;
w3=w3;
u3=u3;
c=c;
}
else
{
x3=x3;
y3=y2-y3;
z3=z2-z3;
w3=w2-w3;
u3=u2-u3;
c=b-c;
c=c/z3;
137
u3=u3/z3;
w3=w3/z3;
z3=z3/z3;
}
if(y4==0)
{
x4=x4;
y4=y4;
z4=z4;
w4=w4;
u4=u4;
d=d;
}
else
{
x4=x4;
y4=y2-y4;
z4=z2-z4;
w4=w2-w4;
u4=u2-u4;
d=b-d;
if(z4==0)
{
d=d/w4;
u4=u4/w4;
w4=w4/w4;
}
138
else
{
d=d/z4;
u4=u4/z4;
w4=w4/z4;
z4=z4/z4;
}
}
if(y5==0)
{
x5=x5;
y5=y5;
z5=z5;
w5=w5;
u5=u5;
d=d;
}
else
{
x5=x5;
y5=y2-y5;
z5=z2-z5;
w5=w2-w5;
u5=u2-u5;
e=b-e;
if(z5==0)
{
139
if(w5==0)
{
e=e/u5;
u5=u5/u5;
}
else
{
e=e/w5;
u5=u5/w5;
w5=w5/w5;
}
}
else
{
e=e/z5;
u5=u5/z5;
w5=w5/z5;
z5=z5/z5;
}
Label88->Caption=FormatFloat("0.###",x1);
Label89->Caption=FormatFloat("0.###",y1);
Label90->Caption=FormatFloat("0.###",z1);
Label91->Caption=FormatFloat("0.###",w1);
Label92->Caption=FormatFloat("0.###",u1);
Label93->Caption=FormatFloat("0.###",a);
140
Label94->Caption=FormatFloat("0.###",x2);
Label95->Caption=FormatFloat("0.###",y2);
Label96->Caption=FormatFloat("0.###",z2);
Label97->Caption=FormatFloat("0.###",w2);
Label98->Caption=FormatFloat("0.###",u2);
Label99->Caption=FormatFloat("0.###",b);
Label100->Caption=FormatFloat("0.###",x3);
Label101->Caption=FormatFloat("0.###",y3);
Label102->Caption=FormatFloat("0.###",z3);
Label103->Caption=FormatFloat("0.###",w3);
Label104->Caption=FormatFloat("0.###",u3);
Label105->Caption=FormatFloat("0.###",c);
Label106->Caption=FormatFloat("0.###",x4);
Label107->Caption=FormatFloat("0.###",y4);
Label108->Caption=FormatFloat("0.###",z4);
Label109->Caption=FormatFloat("0.###",w4);
Label110->Caption=FormatFloat("0.###",u4);
Label111->Caption=FormatFloat("0.###",d);
Label112->Caption=FormatFloat("0.###",x5);
Label113->Caption=FormatFloat("0.###",y5);
Label114->Caption=FormatFloat("0.###",z5);
Label115->Caption=FormatFloat("0.###",w5);
Label116->Caption=FormatFloat("0.###",u5);
Label117->Caption=FormatFloat("0.###",e);
141
if(z4==0)
{
x4=x4;
y4=y4;
z4=z4;
w4=w4;
u4=u4;
d=d;
}
else
{
x4=x4;
y4=y4;
z4=z3-z4;
w4=w3-w4;
u4=u3-u4;
d=c-d;
d=d/w4;
u4=u4/w4;
w4=w4/w4;
}
if(z5==0)
{
x5=x5;
y5=y5;
z5=z5;
w5=w5;
142
u5=u5;
e=e;
}
else
{
x5=x5;
y5=y5;
z5=z3-z5;
w5=w3-w5;
u5=u3-u5;
e=c-e;
e=e/w5;
u5=u5/w5;
w5=w5/w5;
}
Label118->Caption=FormatFloat("0.###",x1);
Label119->Caption=FormatFloat("0.###",y1);
Label120->Caption=FormatFloat("0.###",z1);
Label121->Caption=FormatFloat("0.###",w1);
Label122->Caption=FormatFloat("0.###",u1);
Label123->Caption=FormatFloat("0.###",a);
Label124->Caption=FormatFloat("0.###",x2);
Label125->Caption=FormatFloat("0.###",y2);
Label126->Caption=FormatFloat("0.###",z2);
Label127->Caption=FormatFloat("0.###",w2);
143
Label128->Caption=FormatFloat("0.###",u2);
Label129->Caption=FormatFloat("0.###",b);
Label130->Caption=FormatFloat("0.###",x3);
Label131->Caption=FormatFloat("0.###",y3);
Label132->Caption=FormatFloat("0.###",z3);
Label133->Caption=FormatFloat("0.###",w3);
Label134->Caption=FormatFloat("0.###",u3);
Label135->Caption=FormatFloat("0.###",c);
Label136->Caption=FormatFloat("0.###",x4);
Label137->Caption=FormatFloat("0.###",y4);
Label138->Caption=FormatFloat("0.###",z4);
Label139->Caption=FormatFloat("0.###",w4);
Label140->Caption=FormatFloat("0.###",u4);
Label141->Caption=FormatFloat("0.###",d);
Label142->Caption=FormatFloat("0.###",x5);
Label143->Caption=FormatFloat("0.###",y5);
Label144->Caption=FormatFloat("0.###",z5);
Label145->Caption=FormatFloat("0.###",w5);
Label146->Caption=FormatFloat("0.###",u5);
Label147->Caption=FormatFloat("0.###",e);
if(w5==0)
{
x5=x5;
y5=y5;
144
z5=z5;
w5=w5;
e=e/u5;
u5=u5/u5;
}
else
{
x5=x5;
y5=y5;
z5=z5;
w5=w4-w5;
u5=u4-u5;
e=d-e;
e=e/u5;
u5=u5/u5;
}
Label148->Caption=FormatFloat("0.###",x1);
Label149->Caption=FormatFloat("0.###",y1);
Label150->Caption=FormatFloat("0.###",z1);
Label151->Caption=FormatFloat("0.###",w1);
Label152->Caption=FormatFloat("0.###",u1);
Label153->Caption=FormatFloat("0.###",a);
Label154->Caption=FormatFloat("0.###",x2);
Label155->Caption=FormatFloat("0.###",y2);
Label156->Caption=FormatFloat("0.###",z2);
145
Label157->Caption=FormatFloat("0.###",w2);
Label158->Caption=FormatFloat("0.###",u2);
Label159->Caption=FormatFloat("0.###",b);
Label160->Caption=FormatFloat("0.###",x3);
Label161->Caption=FormatFloat("0.###",y3);
Label162->Caption=FormatFloat("0.###",z3);
Label163->Caption=FormatFloat("0.###",w3);
Label164->Caption=FormatFloat("0.###",u3);
Label165->Caption=FormatFloat("0.###",c);
Label166->Caption=FormatFloat("0.###",x4);
Label167->Caption=FormatFloat("0.###",y4);
Label168->Caption=FormatFloat("0.###",z4);
Label169->Caption=FormatFloat("0.###",w4);
Label170->Caption=FormatFloat("0.###",u4);
Label171->Caption=FormatFloat("0.###",d);
Label172->Caption=FormatFloat("0.###",x5);
Label173->Caption=FormatFloat("0.###",y5);
Label174->Caption=FormatFloat("0.###",z5);
Label175->Caption=FormatFloat("0.###",w5);
Label176->Caption=FormatFloat("0.###",u5);
Label177->Caption=FormatFloat("0.###",e);
u5=e;
w4=d-(e*u4);
z3=c-(e*u3)-(w4*w3);
146
y2=b-(e*u2)-(w4*w2)-(z3*z2);
x1=a-(e*u1)-(w4*w1)-(z3*z1)-(y2*y1);
Label183->Caption=FormatFloat("0.###",x1);
Label184->Caption=FormatFloat("0.###",y2);
Label185->Caption=FormatFloat("0.###",z3);
Label186->Caption=FormatFloat("0.###",w4);
Label187->Caption=FormatFloat("0.###",u5);
Label178->Caption="x1-->";
Label179->Caption="x2-->";
Label180->Caption="x3-->";
Label181->Caption="x4-->";
Label182->Caption="x5-->";
Label188->Caption="RESULTADO:";
Label189->Caption="[";
Label190->Caption="]";
Label191->Caption="[";
Label192->Caption="]";
Label193->Caption="[";
Label194->Caption="]";
Label195->Caption="[";
Label196->Caption="]";
147
Label197->Caption="[";
Label198->Caption="]";
}
//--------------------------------------------------------------------------void __fastcall TForm6::Button3Click(TObject *Sender)
{
Close();
}
//--------------------------------------------------------------------------void __fastcall TForm6::Button2Click(TObject *Sender)
{
Edit1->Text="";
Edit2->Text="";
Edit3->Text="";
Edit4->Text="";
Edit5->Text="";
Edit6->Text="";
Edit7->Text="";
Edit8->Text="";
Edit9->Text="";
Edit10->Text="";
Edit11->Text="";
Edit12->Text="";
Edit13->Text="";
Edit14->Text="";
Edit15->Text="";
Edit16->Text="";
148
Edit17->Text="";
Edit18->Text="";
Edit19->Text="";
Edit20->Text="";
Edit21->Text="";
Edit22->Text="";
Edit23->Text="";
Edit24->Text="";
Edit25->Text="";
Edit26->Text="";
Edit27->Text="";
Edit28->Text="";
Edit29->Text="";
Edit30->Text="";
Edit1->SetFocus();
Label28->Caption="";
Label29->Caption="";
Label30->Caption="";
Label31->Caption="";
Label32->Caption="";
Label33->Caption="";
Label34->Caption="";
Label35->Caption="";
Label36->Caption="";
Label37->Caption="";
Label38->Caption="";
Label39->Caption="";
149
Label40->Caption="";
Label41->Caption="";
Label42->Caption="";
Label43->Caption="";
Label44->Caption="";
Label45->Caption="";
Label46->Caption="";
Label47->Caption="";
Label48->Caption="";
Label49->Caption="";
Label50->Caption="";
Label51->Caption="";
Label52->Caption="";
Label53->Caption="";
Label54->Caption="";
Label55->Caption="";
Label56->Caption="";
Label57->Caption="";
Label58->Caption="";
Label59->Caption="";
Label60->Caption="";
Label61->Caption="";
Label62->Caption="";
Label63->Caption="";
Label64->Caption="";
Label65->Caption="";
Label66->Caption="";
Label67->Caption="";
150
Label68->Caption="";
Label69->Caption="";
Label70->Caption="";
Label71->Caption="";
Label72->Caption="";
Label73->Caption="";
Label74->Caption="";
Label75->Caption="";
Label76->Caption="";
Label77->Caption="";
Label78->Caption="";
Label79->Caption="";
Label80->Caption="";
Label81->Caption="";
Label82->Caption="";
Label83->Caption="";
Label84->Caption="";
Label85->Caption="";
Label86->Caption="";
Label87->Caption="";
Label88->Caption="";
Label89->Caption="";
Label90->Caption="";
Label91->Caption="";
Label92->Caption="";
Label93->Caption="";
Label94->Caption="";
Label95->Caption="";
151
Label96->Caption="";
Label97->Caption="";
Label98->Caption="";
Label99->Caption="";
Label100->Caption="";
Label101->Caption="";
Label102->Caption="";
Label103->Caption="";
Label104->Caption="";
Label105->Caption="";
Label106->Caption="";
Label107->Caption="";
Label108->Caption="";
Label109->Caption="";
Label110->Caption="";
Label111->Caption="";
Label112->Caption="";
Label113->Caption="";
Label114->Caption="";
Label115->Caption="";
Label116->Caption="";
Label117->Caption="";
Label118->Caption="";
Label119->Caption="";
Label120->Caption="";
Label121->Caption="";
Label122->Caption="";
Label123->Caption="";
152
Label124->Caption="";
Label125->Caption="";
Label126->Caption="";
Label127->Caption="";
Label128->Caption="";
Label129->Caption="";
Label130->Caption="";
Label131->Caption="";
Label132->Caption="";
Label133->Caption="";
Label134->Caption="";
Label135->Caption="";
Label136->Caption="";
Label137->Caption="";
Label138->Caption="";
Label139->Caption="";
Label140->Caption="";
Label141->Caption="";
Label142->Caption="";
Label143->Caption="";
Label144->Caption="";
Label145->Caption="";
Label146->Caption="";
Label147->Caption="";
Label148->Caption="";
Label149->Caption="";
Label150->Caption="";
Label151->Caption="";
153
Label152->Caption="";
Label153->Caption="";
Label154->Caption="";
Label155->Caption="";
Label156->Caption="";
Label157->Caption="";
Label158->Caption="";
Label159->Caption="";
Label160->Caption="";
Label161->Caption="";
Label162->Caption="";
Label163->Caption="";
Label164->Caption="";
Label165->Caption="";
Label166->Caption="";
Label167->Caption="";
Label168->Caption="";
Label169->Caption="";
Label170->Caption="";
Label171->Caption="";
Label172->Caption="";
Label173->Caption="";
Label174->Caption="";
Label175->Caption="";
Label176->Caption="";
Label177->Caption="";
Label178->Caption="";
Label179->Caption="";
154
Label180->Caption="";
Label181->Caption="";
Label182->Caption="";
Label183->Caption="";
Label184->Caption="";
Label185->Caption="";
Label186->Caption="";
Label187->Caption="";
Label188->Caption="";
Label189->Caption="";
Label190->Caption="";
Label191->Caption="";
Label192->Caption="";
Label193->Caption="";
Label194->Caption="";
Label195->Caption="";
Label196->Caption="";
Label197->Caption="";
Label198->Caption="";
}
//---------------------------------------------------------------------------
155
MATRIZ [A]
MATRIZ [L]
MATRIZ
[U]
Para encontrar la matriz triangular inferior se busca hacer ceros los valores de
arriba de cada pivote, as como tambin convertir en 1 cada pivote. Se utiliza el
mismo concepto de "factor" explicado anteriormente y se ubican todos los
"factores" debajo de la diagonal segn corresponda en cada uno.
Debido a que [A] = [L][U], al encontrar [L] y [U] a partir de [A] no se altera en
nada la ecuacin. Por lo tanto, si Ax = b, entonces LUx = b, de manera que Ax
= LUx = b.
Esquemticamente se busca lo siguiente:
156
157
PASOS
PARA
RESOLVER
UN SISTEMA DE ECUACIONES POR
EL MTODO DE DESCOMPOSICIN LU
1.
2.
3.
4.
5.
EJEMPLO:
SOLUCIN:
-2 -1
[A] = 5
-1
-4
9
[B] = 7
12
ITERACIN 1
factor 1 = (a21 / a11) = 5 / 4 = 1.25
factor 2 = (a31 / a11) = 1 / 4 = 0.25
Encontrando [U]
fila 2 = - (factor 1) * (fila 1) + (fila 2)
fila 3 = - (factor 2) * (fila 1) + (fila 3)
a11 = a11
a12 = a12
a13 = a13
a21 = - (1.25) * (4) + (5) = 0
[U] =
-2
-1
3.5
0.25
159
2.5
- 0.75
Encontrando [L]
[L] = 1.25 0
0.25 0
ITERACIN 2
Encontrando [U]
[U] =
-2
-1
3.5
0.25
- 0.9285714286
Encontrando [L]
0
160
[L] =
1.25 1
0.25 0.7142857143 1
161
Form1.
ACCIONES POR BOTN.
Botn ENTRAR.
Tiene la funcin de abrir la interfaz del Form2 e iniciar con el programa.
Botn Cerrar programa.
Cierra por completo el programa.
162
Form2.
Botn: U
Tiene la funcin de de obtener el resultado para encontrar a U haciendo ceros
la matriz superior triangular.
Botn: L
Tiene la funcin de obtener el resultado para encontrar a L haciendo ceros la
matriz inferior triangular.
Botn: LU
Este botn arroja el resultado de la multiplicacin de las matrices L y U. La
matriz que arroja es igual a la matriz original [A], ya que, las matrices L y U son
una descomposicin de la matriz [A]; por tal motivo que el producto de las dos
matrices debe resultar la matriz original.
163
Botn: LD=j
Tiene la funcin de encontrar dos coeficientes de la segunda columna y la
primera y tercera fila para conseguir la matriz inversa
Botn: LD=K
Tiene la funcin de encontrar un coeficientes de la tercera columna y tercera
fila para conseguir la matriz inversa.
Botn: Ux=D
Tiene la funcin de salir del form1 y regresar la portada del formulario principal.
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
165
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
TForm1 *Form2;
//--------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
Form2.
//--------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
166
TForm2 *Form2;
TForm2 *Form3;
double A[3][3],U[3][3],L[3][3],LU[3][3],I[3][3],Z[3][3],X[3][3],V[3][3],T[3][3], a, b, det;
int i=1, j=1, C[3][3], r=1, s=1;
double B[3][3], p, n, l;
//--------------------------------------------------------------------------__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
}
j++;
if(j==4){
i++;
j=1;
}
if(A[1][1]==0){
Label3->Caption="No puedo resolver tu matriz";
}
if(i==4){
{Label7->Caption="Introduce Valores de B presiona U";}
a= (A[1][1]*A[2][2]*A[3][3])+(A[2][1]*A[3][2]*A[1][3])+(A[3][1]*A[1][2]*A[2][3]);
b= (A[1][3]*A[2][2]*A[3][1])+(A[2][3]*A[3][2]*A[1][1])+(A[3][3]*A[1][2]*A[2][1]);
det= a-b;
if(det==0){
Label3->Caption="La Matriz no tiene Inversa";
}
}
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button2Click(TObject *Sender)
{
T[1][1]=A[1][1];
T[1][2]=A[1][2];
T[1][3]=A[1][3];
for(int i=2; i<=3; i++){
for(int j=1; j<=3; j++){
T[2][j]=A[2][j]-((A[2][1]/A[1][1]*(A[1][j])));
}
}
for(int i=3; i<=3; i++){
168
L[1][1]=1;
L[1][2]=0;
L[1][2]=0;
L[2][1]=A[2][1]/A[1][1];
L[2][2]=1;
L[2][3]=0;
L[3][1]=A[3][1]/A[1][1];
L[3][2]=T[3][2]/T[2][2];
L[3][3]=1;
Edit20->Text=AnsiString(L[1][1]);
Edit21->Text=AnsiString(L[1][2]);
Edit22->Text=AnsiString(L[1][3]);
Edit23->Text=AnsiString(L[2][1]);
Edit24->Text=AnsiString(L[2][2]);
Edit25->Text=AnsiString(L[2][3]);
Edit26->Text=AnsiString(L[3][1]);
Edit27->Text=AnsiString(L[3][2]);
Edit28->Text=AnsiString(L[3][3]);
Label7->Caption="Oprima LU";
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button4Click(TObject *Sender)
{
LU[1][1]=A[1][1];
LU[1][2]=A[1][2];
LU[1][3]=A[1][3];
LU[2][1]=A[2][1];
LU[2][2]=A[2][2];
LU[2][3]=A[2][3];
LU[3][1]=A[3][1];
LU[3][2]=A[3][2];
170
LU[3][3]=A[3][3];
Edit29->Text=AnsiString(LU[1][1]);
Edit30->Text=AnsiString(LU[1][2]);
Edit31->Text=AnsiString(LU[1][3]);
Edit32->Text=AnsiString(LU[2][1]);
Edit33->Text=AnsiString(LU[2][2]);
Edit34->Text=AnsiString(LU[2][3]);
Edit35->Text=AnsiString(LU[3][1]);
Edit36->Text=AnsiString(LU[3][2]);
Edit37->Text=AnsiString(LU[3][3]);
Label7->Caption="Oprima LD=i";
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button5Click(TObject *Sender)
{
Z[1][1]=1;
Z[2][1]=(-1*L[2][1]*L[1][1]+L[2][3]);
Z[3][1]=(-1*L[3][2]*Z[2][1]+(-1*L[3][1]));
Edit38->Text=AnsiString(Z[1][1]);
Edit39->Text=AnsiString(Z[2][1]);
Edit40->Text=AnsiString(Z[3][1]);
Label7->Caption="Oprima LD=j";
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button6Click(TObject *Sender)
{
Z[1][2]=0;
Z[2][2]=1;
Z[3][2]=1*(-L[3][2]);
Edit41->Text=AnsiString(Z[1][2]);
Edit42->Text=AnsiString(Z[2][2]);
171
Edit43->Text=AnsiString(Z[3][2]);
Label7->Caption="Oprima LD=k";
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button7Click(TObject *Sender)
{
Z[1][3]=0;
Z[2][3]=0;
Z[3][3]=1*L[3][3];
Edit44->Text=AnsiString(Z[1][3]);
Edit45->Text=AnsiString(Z[2][3]);
Edit46->Text=AnsiString(Z[3][3]);
Label7->Caption="Sigue.. Ux=D";
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button8Click(TObject *Sender)
{
X[3][1]=Z[3][1]/U[3][3];
X[2][1]=((Z[2][1])-((U[2][3])*(X[3][1])))/(U[2][2]);
X[1][1]=((Z[1][1])-(U[1][3])*(X[3][1])-(U[1][2])*(X[2][1]))/(U[1][1]);
Edit47->Text=AnsiString(Z[1][1]);
Edit48->Text=AnsiString(Z[2][1]);
Edit49->Text=AnsiString(Z[3][1]);
Label7->Caption="Sigue.. Uy=D";
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button9Click(TObject *Sender)
{
X[3][2]=Z[3][2]/U[3][3];
X[2][2]=((Z[2][2])-((U[2][3])*(X[3][2])))/(U[2][2]);
X[1][2]=((Z[1][2])-(U[1][3])*(X[3][2])-(U[1][2])*(X[2][2]))/(U[1][1]);
172
Edit50->Text=AnsiString(Z[1][2]);
Edit51->Text=AnsiString(Z[2][2]);
Edit52->Text=AnsiString(Z[3][2]);
Label7->Caption="Sigue.. Uz=D";
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button10Click(TObject *Sender)
{
X[3][3]=Z[3][3]/U[3][3];
X[2][3]=((Z[2][3])-((U[2][3])*(X[3][3])))/(U[2][2]);
X[1][3]=((Z[1][3])-(U[1][3])*(X[3][3])-(U[1][2])*(X[2][3]))/(U[1][1]);
Edit53->Text=AnsiString(Z[1][3]);
Edit54->Text=AnsiString(Z[2][3]);
Edit55->Text=AnsiString(Z[3][3]);
Label7->Caption="Da Click En Matriz Inversa";
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button11Click(TObject *Sender)
{
Edit56->Text=AnsiString(X[1][1]);
Edit57->Text=AnsiString(X[1][2]);
Edit58->Text=AnsiString(X[1][3]);
Edit59->Text=AnsiString(X[2][1]);
Edit60->Text=AnsiString(X[2][2]);
Edit61->Text=AnsiString(X[2][3]);
Edit62->Text=AnsiString(X[3][1]);
Edit63->Text=AnsiString(X[3][2]);
Edit64->Text=AnsiString(X[3][3]);
Label3->Caption="Encontrastes la [A]-1";
}
//--------------------------------------------------------------------------173
Edit16->Text="";
Edit17->Text="";
Edit18->Text="";
Edit19->Text="";
Edit20->Text="";
Edit21->Text="";
Edit22->Text="";
Edit23->Text="";
Edit24->Text="";
Edit25->Text="";
Edit26->Text="";
Edit27->Text="";
Edit28->Text="";
Edit29->Text="";
Edit30->Text="";
Edit31->Text="";
Edit32->Text="";
Edit33->Text="";
Edit34->Text="";
Edit35->Text="";
Edit36->Text="";
Edit37->Text="";
Edit38->Text="";
Edit39->Text="";
Edit40->Text="";
Edit41->Text="";
Edit42->Text="";
Edit43->Text="";
Edit44->Text="";
Edit45->Text="";
Edit46->Text="";
175
Edit47->Text="";
Edit48->Text="";
Edit49->Text="";
Edit50->Text="";
Edit51->Text="";
Edit52->Text="";
Edit53->Text="";
Edit54->Text="";
Edit55->Text="";
Edit56->Text="";
Edit57->Text="";
Edit58->Text="";
Edit59->Text="";
Edit60->Text="";
Edit61->Text="";
Edit62->Text="";
Edit63->Text="";
Edit64->Text="";
Label3->Caption="";
Label7->Caption="";
i=1;
j=1;
r=1;
s=1;
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button14Click(TObject *Sender)
{
Close();
}
//--------------------------------------------------------------------------176
p=(X[1][1]*B[1][1]+X[1][2]*B[2][1]+X[1][3]*B[3][1]);
l=(X[2][1]*B[1][1]+X[2][2]*B[2][1]+X[2][3]*B[3][1]);
n=(X[3][1]*B[1][1]+X[3][2]*B[2][1]+X[3][3]*B[3][1]);
Edit67->Text=AnsiString(p);
Edit68->Text=AnsiString(l);
Edit69->Text=AnsiString(n);
Label7->Caption="Haz encontrado la solucion";
}
177
Form3.
//---------------------------------------------------------------------------
#include <vcl.h>
178
#pragma hdrstop
#include "Unit3.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
TForm3 *Form3;
TForm3 *Form2;
179
F(x)=
x
F(x,x)
F(x)=
F(x)=
F(x)=
F(x,x)
F(x,x,x)
F(x,x,x)
F(x,x,x,x)
F(x,x)
181
2.71828
7.38906
20.08654
(4.67078-1.71828)/2=1.47625, (12.6989-4.67078)/2=4.01406
F(x)= 1+1.71828(1.5)+1.47625(1.5)(1.5-1)+0.84553(1.5)(1.5-1)(1.5-2)
F(x)= 4.3675
El clculo exacto si lo situamos en la frmula es 4.48 por lo cual el margen de
error es muy pequeo
El polinomio obtenido satisface a los puntos de esa funcin.
GRAFICA:
Cdigo de programacin
183
Interfaz grfica:
Su programacin:
//--------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
#include "Unit3.h"
//---------------------------------------------------------------------------
Interfaz grfica:
Su programacin:
//---------------------------------------------------------------------------
185
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#include <math.h>
double
a,a1,a2,b0,b1,b2,b3,x0,x1,x2,x3,x,y,y0,y1,y2,y3,Inicio,Fin,k,f,g,h,i,j,p,q,r,s,t,Fx1,Fx2,Fx3,Fx4,Fx5;
TForm2 *Form2;
//--------------------------------------------------------------------------__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
y0=Edit5->Text.ToDouble();
y1=Edit6->Text.ToDouble();
b0=y0;
b1=(y1-y0)/(x1-x0);
186
Label3->Caption=(b0);
Label4->Caption=(b1);
}
//---------------------------------------------------------------------------
x0=Edit1->Text.ToDouble();
x1=Edit2->Text.ToDouble();
x2=Edit3->Text.ToDouble();
y0=Edit5->Text.ToDouble();
y1=Edit6->Text.ToDouble();
y2=Edit7->Text.ToDouble();
b0=y0;
b1=(y1-y0)/(x1-x0);
a=(y2-y1)/(x2-x1);
b2=(a-b1)/(x2-x0);
Label3->Caption=(b0);
Label4->Caption=(b1);
Label5->Caption=(b2);
}
//---------------------------------------------------------------------------
x0=Edit1->Text.ToDouble();
187
x1=Edit2->Text.ToDouble();
x2=Edit3->Text.ToDouble();
x3=Edit4->Text.ToDouble();
y0=Edit5->Text.ToDouble();
y1=Edit6->Text.ToDouble();
y2=Edit7->Text.ToDouble();
y3=Edit8->Text.ToDouble();
b0=y0;
b1=(y1-y0)/(x1-x0);
a=(y2-y1)/(x2-x1);
b2=(a-b1)/(x2-x0);
a1=(y3-y2)/(x3-x2);
a2=(a1-a)/(x3-x1);
b3=(a2-b2)/(x3-x0);
Label3->Caption=(b0);
Label4->Caption=(b1);
Label5->Caption=(b2);
Label6->Caption=(b3);
}
//---------------------------------------------------------------------------
x=Edit9->Text.ToDouble();
y=b0+b1*(x-x0)+b2*(x-x0)*(x-x1)+b3*(x-x0)*(x-x1)*(x-x2);
Edit10->Text=AnsiString(y);
188
}
//---------------------------------------------------------------------------
Form3->Canvas->Pen->Color=clTeal;
Form3->Canvas->Pen->Width=2;
Form3->Canvas->PenPos=TPoint(400,200);
Form3->Canvas->LineTo(830,200);
Form3->Canvas->Pen->Color=clTeal;
Form3->Canvas->Pen->Width=2;
Form3->Canvas->PenPos=TPoint(600,50);
Form3->Canvas->LineTo(600,360);
Form3->Canvas->Pen->Color=clTeal;
Form3->Canvas->Pen->Color=0x009747EF;
Inicio=-10;
Fin=10;
x=Inicio;
y=b0+b1*(x-x0)+b2*(x-x0)*(x-x1)+b3*(x-x0)*(x-x1)*(x-x2);
Form3->Canvas->PenPos=TPoint(600+14*Inicio,200-5*y);
for(x=Inicio;x<Fin;x++)
189
{
y=b0+b1*(x-x0)+b2*(x-x0)*(x-x1)+b3*(x-x0)*(x-x1)*(x-x2);
Form3->Canvas->LineTo(600+15*x,200-5*y);
}
Form3->Canvas->Pen->Color=clBlack;
Form3->Canvas->Pen->Width=2;
Form3->Canvas->PenPos=TPoint(400,200);
Form3->Canvas->LineTo(830,200);
Form3->Canvas->Pen->Width=2;
Form3->Canvas->PenPos=TPoint(600,50);
Form3->Canvas->LineTo(600,360);
Form3->Canvas->Pen->Color=0x009747EF;
Inicio=-10;
Fin=10;
x=Inicio;
y=b0+b1*(x-x0)+b2*(x-x0)*(x-x1)+b3*(x-x0)*(x-x1)*(x-x2);
Form3->Canvas->PenPos=TPoint(600+15*Inicio,200-5*y);
for(x=Inicio;x<Fin;x++)
{
y=b0+b1*(x-x0)+b2*(x-x0)*(x-x1)+b3*(x-x0)*(x-x1)*(x-x2);
Canvas->PenPos=TPoint(600+15*x,200-5*y);
}
Form3->Canvas->Pen->Color=clTeal;
Form3->Canvas->Pen->Width=2;
Form3->Canvas->PenPos=TPoint(400,200);
Form3->Canvas->LineTo(830,200);
190
Form3->Canvas->Pen->Color=clTeal;
Form3->Canvas->Pen->Width=2;
Form3->Canvas->PenPos=TPoint(600,50);
Form3->Canvas->LineTo(600,360);
Form3->Canvas->Pen->Color=clTeal;
Form3->Canvas->Pen->Color=0x009747EF;
Inicio=-10;
Fin=10;
x=Inicio;
y=b0+b1*(x-x0)+b2*(x-x0)*(x-x1)+b3*(x-x0)*(x-x1)*(x-x2);
Form3->Canvas->PenPos=TPoint(600+14*Inicio,200-5*y);
for(x=Inicio;x<Fin;x++)
{
y=b0+b1*(x-x0)+b2*(x-x0)*(x-x1)+b3*(x-x0)*(x-x1)*(x-x2);
Form3->Canvas->LineTo(600+15*x,200-5*y);
}
}
//---------------------------------------------------------------------------
Edit5->Text="";
Edit6->Text="";
Edit7->Text="";
Edit8->Text="";
Edit9->Text="";
Edit10->Text="";
Edit11->Text="";
Edit12->Text="";
Edit13->Text="";
Edit14->Text="";
Edit15->Text="";
Edit16->Text="";
Edit17->Text="";
Label3->Caption="";
Label4->Caption="";
Label5->Caption="";
Label6->Caption="";
Edit11->SetFocus();
}
//---------------------------------------------------------------------------
192
f=Edit11->Text.ToDouble ();
g=Edit12->Text.ToDouble ();
h=Edit13->Text.ToDouble ();
i=Edit14->Text.ToDouble ();
j=Edit15->Text.ToDouble ();
p=Edit1->Text.ToDouble ();
q=Edit2->Text.ToDouble ();
r=Edit3->Text.ToDouble ();
s=Edit4->Text.ToDouble ();
t=Edit16->Text.ToDouble ();
Fx1=f*(pow(p,4))+g*(pow(p,3))+h*(pow(p,2))+i*p+j;
Edit5->Text=AnsiString (Fx1);
Fx2=f*(pow(q,4))+g*(pow(q,3))+h*(pow(q,2))+i*q+j;
Edit6->Text=AnsiString (Fx2);
Fx3=f*(pow(r,4))+ g*(pow(r,3))+h*(pow(r,2))+i*r+j;
Edit7->Text=AnsiString (Fx3);
Fx4=f*(pow(s,4))+g*(pow(s,3))+h*(pow(s,2))+i*s+j;
Edit8->Text=AnsiString (Fx4);
Fx5=f*(pow(t,4))+g*(pow(t,3))+h*(pow(t,2))+i*t+j;
Edit17->Text=AnsiString(Fx5);
}
//--------------------------------------------------------------------------Interfaz grfica:
193
Su cdigo de programacin:
//--------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
#include "Unit3.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
#include <math.h>
double a,a1,a2,b0,b1,b2,b3,x0,x1,x2,x3,x,y,y0,y1,y2,y3,Inicio,Fin,k;
TForm3 *Form3;
//--------------------------------------------------------------------------__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------194
Close();
Form1->Visible=true;
}
//---------------------------------------------------------------------------
195
Derivacin
Cuando escuchamos la palabra derivada, siempre lo relacionamos con el
cambio de pendiente que sufre una funcin.
Funciones
3 2
4 3
Funciones
1
Datos
= 6 + 7
13
Datos
19
25
196
Derivacin numrica
Datos
X0
Y0
X1
Y1
Datos
197
0 1 2
0 1 2
198
() = () + ( 0 )( 1 )( 2 )
()
3!
Polinomio interpolador
1 0
1 0
2 1
2 1
() = 0 +
() =
2 1 1 0
2 1 1 0
2 0
1 0
2 21 + 0
( 0 ) +
( 0 )( 1 )
22
1 0 2 21 + 0
( 0 ) + ( 1 )
+
22
Evaluando en 0 , 1 , 2 :
(Por la derecha):
(0 ) =
1 0 2 21 + 0
(0 0 ) + (0 1 )
+
22
(0 ) =
1 0 2 21 + 0 2 + 41 30
2
2
(Central):
(1 ) =
1 0 2 21 + 0
(1 0 ) + (1 1 )
+
22
(1 ) =
1 0 2 21 + 0
2 0
+
=
2
2
(Por la izquierda):
(2 ) =
(2 ) =
1 0 2 21 + 0
(2 0 ) + (2 1 )
+
22
1 0 3(2 21 + 0 ) 21 20 + 32 61 + 30
+
=
2
2
32 41 + 0
=
2
199
()
( 0 )( 1 )( 2 )
3!
= ( 0 )( 1 ) + ( 0 )( 2 ) + ( 1 )( 2 )
()
3!
Evaluando:
(0 ) =
2
3
(1 ) =
(2 )
()
2
()
6
2
= ()
3
+ ()
Derecha
(1 ) =
1 0
()
Izquierda
2 + 41 30 2
+ ()
2
3
Derecha
Orden 1
=
Orden 2
(0 ) =
200
() =
()
(0 ) =
Izquierda
Derecha
3 + 62 31 20 3
+ ()
6
12
Central
0 61 + 32 + 23 3
()
6
12
Central
=
(2 ) =
(3 )
32 41 + 0 2
=
+ ()
2
3
Central
23 92 + 181 110 3
()
6
8
(1 ) =
Orden 3
2 0 2
()
2
6
113 182 + 91 20 3
=
+ ()
6
4
Izquierda
201
Interfaz grafica:
//---------------------------------------------------------------#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
202
//---------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
int i=2,a,b;
double Y[100],y0,y1,y2,h,der,cen,izq;
TForm1 *Form1;
//---------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------void __fastcall TForm1::FormActivate(TObject *Sender)
{
Edit1->SetFocus();
}
//---------------------------------------------------------------//botn capturar Y[i]
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Y[i]=Edit1->Text.ToDouble();
Label2->Caption="n= "+AnsiString(i-1);
Edit1->Text="";
Edit1->SetFocus();
a=i-4;
i++;
b=1;
}
//---------------------------------------------------------------//botn mostrar datos +
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if(b==1){i=-1;}
if(i<a){i++;}
Edit3->Text=AnsiString(Y[i]);
Edit4->Text=AnsiString(Y[i+1]);
Edit5->Text=AnsiString(Y[i+2]);
Edit6->Text=AnsiString(Y[i+3]);
Edit7->Text=AnsiString(Y[i+4]);
b=0;
}
//---------------------------------------------------------------//botn mostrar datos void __fastcall TForm1::Button3Click(TObject *Sender)
{
if(b==1){i=1;}
if(i!=0){i--;}
Edit3->Text=AnsiString(Y[i]);
Edit4->Text=AnsiString(Y[i+1]);
Edit5->Text=AnsiString(Y[i+2]);
Edit6->Text=AnsiString(Y[i+3]);
203
Edit7->Text=AnsiString(Y[i+4]);
b=0;
}
//---------------------------------------------------------------//botn primera
void __fastcall TForm1::Button4Click(TObject *Sender)
{
h=Edit2->Text.ToDouble();
y0=Edit5->Text.ToDouble();
y1=Edit6->Text.ToDouble();
y2=Edit7->Text.ToDouble();
der=(-y2+(4*y1)-(3*y0))/(2*h);
cen=(y2-y0)/(2*h);
izq=((3*y2)-(4*y1)+y0)/(2*h);
Edit8->Text=AnsiString(der);
Edit9->Text=AnsiString(cen);
Edit10->Text=AnsiString(izq);
}
//----------------------------------------------------------------
//botn reset
void __fastcall TForm1::Button6Click(TObject *Sender)
{
Edit1->Text="";
Edit2->Text="";
Edit3->Text="";
Edit4->Text="";
Edit5->Text="";
Edit6->Text="";
Edit7->Text="";
Edit8->Text="";
Edit9->Text="";
Edit10->Text="";
Edit11->Text="";
Edit1->SetFocus();
Label2->Caption="n=";
a=2;
}
//----------------------------------------------------------------
204
205
INTERPRETACIN DE LA DERIVADA
INTERPRETACIN GEOMTRICA DE LA DERIVADA
206
207
LA DERIVACIN NUMRICA
Es una de las tcnicas de anlisis numrico para poder calcular una
aproximacin a la derivada de una funcin en un punto utilizando valores y
propiedades.
La derivada es de uso comn en las matemticas y la ingeniera, ya que es la
prctica de muchas funciones con las que se trabaja. Es necesario proceder a
calcular el valor de algunas derivadas de algunas funciones en un punto
concreto. En este tipo de situaciones no se puede utilizar el concepto riguroso
de derivada por desconocimiento de la expresin de una funcin.
De esta manera surge la necesidad de disear mtodos numricos que
permitan aproximar el valor de las derivadas de una funcin en algn punto.
Los mtodos de derivacin numrica se desarrollaron con el fin de aproximar
algn valor buscado. La diferencia numrica es muy til en casos en los cuales
se tienen una funcin cuya derivada es difcil o complicada de hallar, o en
caso en los cuales no se tienen una funcin explicita sino una serie de datos
experimentales.
El problema de la derivacin numrica consiste en la evaluacin de la
derivada de la funcin de un punto, cuando nicamente conocemos los valores
de la funcin en una coleccin de puntos X0, X1...Xn.
La derivada es una propiedad esencialmente local, por lo cual deberemos
aproximar la funcin lo ms fielmente posible en el entorno inmediato del
punto en el que la queremos evaluar. La frmula de la derivacin numrica
aparece en el desarrollo de algoritmos para la solucin de problemas de
contorno en ecuaciones diferenciales ordinarias.
208
j=0, , n,
209
REGRESIVAS:
Entonce
s, para
x= xj, se tiene la frmula:
CENTRALES:
210
211
Mediante este mismo procso se pueden obtener frmulas para las derivadas de
orden tercero, cuarto, etc.
212
INTERFAZ GRFICA
213
PROGRAMACIN
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
#include "Unit3.h"
#include "Unit4.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner)
214
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
Button3->Visible=True;
}
//---------------------------------------------------------------------------
215
Form2->Show();
}
//--------------------------------------------------------------------------void __fastcall TForm1::Button2Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
FORM 2
#pragma package(smart_init)
#pragma resource "*.dfm"
double x0, x1, x2, x3, x4, D, h, x, xi, xii, Fx, Fxi, Fxii, F1, F2, F3;
double Fxx, Fxx1, Fxx2, xi2, x2ii, Fxi2, Fx2ii, D1;
TForm3 *Form3;
//--------------------------------------------------------------------------216
}
//---------------------------------------------------------------------------
D=2;
}
//--------------------------------------------------------------------------void __fastcall TForm3::RadioButton3Click(TObject *Sender)
{
D=3;
}
//--------------------------------------------------------------------------217
Image1->Visible=True;
Image2->Visible=False;
x4= Edit1->Text.ToDouble();
x3= Edit2->Text.ToDouble();
x2= Edit3->Text.ToDouble();
x1= Edit4->Text.ToDouble();
x0= Edit5->Text.ToDouble();
h=Edit7->Text.ToDouble();
x=Edit6->Text.ToDouble();
xi= x+h;
xii= x-h;
if (D==1)
218
Edit8->Text=AnsiString(F1);
Edit15->Text=AnsiString(x);
Edit16->Text=AnsiString(xi);
}
if (D==3)
{
Edit10->Text=AnsiString(F3);
Edit15->Text=AnsiString(x);
}
if (D==2)
{
Edit9->Text=AnsiString(F2);
219
Edit14->Text=AnsiString(xii);
Edit16->Text=AnsiString(xi);
}
//--------------------------------------------------------------------------void __fastcall TForm3::Button3Click(TObject *Sender)
{
Close();
}
//--------------------------------------------------------------------------void __fastcall TForm3::RadioButton4Click(TObject *Sender)
{
D1=1;
}
//--------------------------------------------------------------------------220
D1=2;
}
//---------------------------------------------------------------------------
D1=3;
}
//---------------------------------------------------------------------------
Image2->Visible=True;
Image1->Visible=False;
221
xi2= x+(2*h);
x2ii= x- (2*h);
if (D1==1)
{
F= (Fxi2- (2*Fxi)+ Fx)/ (h*h) ;
Edit11->Text=AnsiString(Fx);
}
if (D1==3)
{
Fxx1= (Fxi2- Fxi-Fx+Fx2ii)/ (h*h*2) ;
Edit13->Text=AnsiString(Fxx1);
222
if (D1==2)
{
Fxx2= (Fxi2-(2*Fx)+Fx2ii)/ (h*h*4) ;
Edit12->Text=AnsiString(Fxx2);
}
//---------------------------------------------------------------------------
Edit12->Text="";
Edit13->Text="";
Edit14->Text="";
Edit15->Text="";
Edit16->Text="";
Edit1->SetFocus();
FORM 3
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include "Unit4.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
224
double g, y0, y1, y2, y3, Fy0, Fy1, Fy2, Fy3, a0, a1,a2, p1, p2,p3, yi, pol,
p2i;
double w, w2,poli, polii,H, ai1, ai2, ai3, v;
TForm4 *Form4;
//--------------------------------------------------------------------------__fastcall TForm4::TForm4(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
Fy0=Edit1->Text.ToDouble();
Fy1=Edit2->Text.ToDouble();
Fy2=Edit3->Text.ToDouble();
Fy3=Edit4->Text.ToDouble();
y0=Edit5->Text.ToDouble();
y1=Edit6->Text.ToDouble();
y2=Edit7->Text.ToDouble();
y3=Edit8->Text.ToDouble();
225
H=Edit10->Text.ToDouble();
df=Edit9->Text.ToDouble();
ai1=(a0*(yi-y1)+(yy2));
ai3=(a2)*(yi-1));
pol= ai1+ai2+ai3;
poli= pol+H;
pol= pol-H;
Edit12->Text=AnsiString(pol);
Edit11->Text=AnsiString(polii);
Edit13->Text=AnsiString(poli);
226
Edit14->Text=AnsiString(Fxx);
Edit15->Text=AnsiString(g3) ;
Edit16->Text=AnsiString(gg2) ;
}
//--------------------------------------------------------------------------void __fastcall TForm4::RadioButton1Click(TObject *Sender)
{
v=1;
}
//--------------------------------------------------------------------------void __fastcall TForm4::RadioButton2Click(TObject *Sender)
{
v=2;
}
//--------------------------------------------------------------------------void __fastcall TForm4::RadioButton3Click(TObject *Sender)
{
v=3;
}
//--------------------------------------------------------------------------227
10.
Este problema tambin puede ser enunciado como un problema de valor inicial
para una ecuacin diferencial ordinaria, como sigue:
aproximacin, que depende del mtodo que se utilice y de qu tan fino sea,
puede llegar a ser tan pequeo que es posible obtener un resultado idntico a
la solucin analtica en las primeras cifras decimales.
Formula de newton-cotes
En anlisis numrico las frmulas de Newton-Cotes (nombradas as por Isaac
Newton y Roger Cotes) son un grupo de frmulas de integracin numrica de
tipo interpolatorio, en las cuales se evala la funcin en puntos equidistantes,
para as hallar un valor aproximado de la integral. Cuantos ms intervalos se
divida la funcin ms preciso ser el resultado.
Este mtodo es eficiente si se conocen los valores de la funcin en puntos
igualmente separados. Si se pueden cambiar los puntos en los cuales la
funcin es evaluada otros mtodos como la cuadratura de Gauss son
probablemente ms eficientes.
Estas a su vez se dividen en:
Formulas cerradas de newton-cotes
Reglas de Simpson
En anlisis numrico, la regla o mtodo de Simpson, nombrada as en honor a
Thomas Simpson (y a veces llamada regla de Kepler), es un mtodo de
integracin numrica para obtener el valor aproximado de integrales definidas.
Se dividen en dos:
Regla de Simpson 1/3
Regla de simpson3/8
Regla de simpson3/8
230
231
Esta programa est basado en la regla de Simpson 3/8, est programado para
integrar funciones de quinto grado y obtener su cuarta derivada, el uso del
programa de es fcil a continuacin una serie de pasos de cmo utilizar el
programa:
1) Introducimos los lmites de la funcin que sera de a a b y capturamos
a,b.
232
{
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button1Click(TObject *Sender)
{
c =Edit6->Text.ToDouble();
d =Edit7->Text.ToDouble();
e =Edit8->Text.ToDouble();
f =Edit9->Text.ToDouble();
g =Edit10->Text.ToDouble();
h1 =Edit11->Text.ToDouble();
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button2Click(TObject *Sender)
{
a= Edit1->Text.ToDouble();
b= Edit2->Text.ToDouble();
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button3Click(TObject *Sender)
{
h=b-a;
hf=h/3;
Xm=a+hf;
Xn=Xm+hf;
Edit3->Text=AnsiString(hf);
Edit4->Text=AnsiString(Xm);
Edit5->Text=AnsiString(Xn);
a2=pow(a,2);
a3=pow(a,3);
a4=pow(a,4);
235
a5=pow(a,5);
a1=a;
b2=pow(b,2);
b3=pow(b,3);
b4=pow(b,4);
b5=pow(b,5);
b1=b;
Xm2=pow(Xm,2);
Xm3=pow(Xm,3);
Xm4=pow(Xm,4);
Xm5=pow(Xm,5);
Xm1=Xm;
Xn2=pow(Xn,2);
Xn3=pow(Xn,3);
Xn4=pow(Xn,4);
Xn5=pow(Xn,5);
Xn1=Xn;
}
//--------------------------------------------------------------------------void __fastcall TForm2::Image5Click(TObject *Sender)
{
Close();
}
//--------------------------------------------------------------------------void __fastcall TForm2::Image1Click(TObject *Sender)
{
fa=(c*a5)+(d*a4)+(e*a3)+(f*a2)+(g*a1)+h1;
fXm=(c*Xm5)+(d*Xm4)+(e*Xm3)+(f*Xm2)+(g*Xm1)+h1;
fXn=(c*Xn5)+(d*Xn4)+(e*Xn3)+(f*Xn2)+(g*Xn1)+h1;
fb=(c*b5)+(d*b4)+(e*b3)+(f*b2)+(g*b1)+h1;
Edit13->Text=AnsiString(fa);
236
Edit14->Text=AnsiString(fXm);
Edit15->Text=AnsiString(fXn);
Edit16->Text=AnsiString(fb);
fsus=fa+(3*fXm)+(3*fXn)+fb;
k=(.125)*h;
inte= k*fsus ;
Edit12->Text=AnsiString(inte);
}
//--------------------------------------------------------------------------void __fastcall TForm2::Image4Click(TObject *Sender)
{
Edit1->Text="";
Edit2->Text="";
Edit3->Text="";
Edit4->Text="";
Edit5->Text="";
Edit6->Text="";
Edit7->Text="";
Edit8->Text="";
Edit9->Text="";
Edit10->Text="";
Edit11->Text="";
Edit12->Text="";
h=0;
fXm=0;
fXn=0;
Edit13->Text="";
Edit14->Text="";
Edit15->Text="";
Edit16->Text="";
Edit17->Text="";
Edit18->Text="";
Edit19->Text="";
237
Edit20->Text="";
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button4Click(TObject *Sender)
{
A5=c*5;
B4=d*4;
C3=e*3;
D2=f*2;
E1=g;
A4=A5*4;
B3=B4*3;
C2=C3*2;
D1=D2;
A3=A4*3;
B2=B3*2;
C1=C2;
A2=A3*2;
Edit17->Text=AnsiString(A2);
B1=B2;
Edit18->Text=AnsiString(B1);
}
//---------------------------------------------------------------------------
11.
Introduccin
En el siguiente trabajo se hablara de las ecuaciones diferenciales ordinarias de
primer orden y como poder resolverla usando el mtodo de series de Taylor,
daremos una explicacin amplia de que es una ecuacin diferencial y sus
clasificaciones, en que consiste el mtodo de series de Taylor y por supuesto
diremos quin es Taylor.
Despus combinaremos la informacin de ecuaciones diferenciales y la serie
de Taylor, para poder resolver dichas ecuaciones e idearemos un programa
que nos ayude en el proceso de resolucin de las ecuaciones diferenciales
ordinarias de primer orden.
239
Fundamento terico
Una ecuacin diferencial es una ecuacin que relaciona de manera no trivial a
una funcin desconocida y una o ms derivadas de esta funcin desconocida
con respecto a una o ms variables independientes. Si la funcin desconocida
depende de una sola variable la ecuacin diferencial se llama ordinaria, y si
depende de ms de una variable, se llama parcial.
La frase de manera no trivial que hemos usado en la definicin anterior
tiene como propsito descartar ecuaciones diferenciales que satisfacen la
definicin, pero son realmente identidades, es decir, son siempre verdaderas
sin importar quin sea la funcin desconocida.
(, , , , , ) =
, , , , , =
= (, , , , , )
+ = ,
+ = y
+ = +
+ = ,
240
+ =
241
242
Edmonton
Biografa de Brook Taylor.
Ciudad de Canad
Brook Taylor
(18/08/1685 - 29/12/1731)
Matemtico britnico
Definicin de mtodo.
La serie de Taylor es una herramienta matemtica que si se usa
aproximadamente facilita muchos los clculos de aproximacin de funciones.
La idea fundamental detrs de la serie de Taylor es la de poder aproximar los
valores de una funcin () para cualquier punto "", a partir de tener un punto
de referencia "" situado a una distancia "" del primero y todo esto a partir de
la creacin de un polinomio basado en una serie de potencias infinita para la
cual sea posible de manera sistemtica calcular sus coeficientes.
()
()
() ()
(
(
( ) +
() = () +
) +
) +
!
!
!
()
( )
+
!
de
una
manera
ms
compacta
como
la
( )
( )
!
imposible:
el
resultado
fueron
las paradojas
de
Zenn.
Posteriormente, Aristteles propuso una resolucin filosfica a la paradoja,
pero el contenido matemtico de esta no qued resuelto hasta que lo
retomaron Demcrito y despus Arqumedes.
Fue a travs del mtodo exhaustivo de Arqumedes que un nmero infinito de
subdivisiones geomtricas progresivas podan alcanzar un resultado
trigonomtrico finito. Independientemente, Liu Hui utiliz un mtodo similar
cientos de aos despus.
En el siglo XIV, los primeros ejemplos del uso de series de Taylor y mtodos
similares fueron dados por Madhava de Sangamagrama. A pesar de que hoy
en da ningn registro de su trabajo ha sobrevivido a los aos, escritos de
matemticos hindes posteriores sugieren que l encontr un nmero de casos
especiales de la serie de Taylor, incluidos aquellos para las funciones
trigonomtricas del seno, coseno, tangente y arco-tangente.
En el siglo XVII, James Gregory tambin trabaj en esta rea y public varias
series de Maclaurin. Pero en 1715 se present una forma general para
construir estas series para todas las funciones para las que existe y fue
presentado por Brook Taylor, de quin recibe su nombre. Las series de
Maclaurin fueron nombradas as por Colin Maclaurin, un profesor de Edimburgo,
quin public el caso especial de las series de Taylor en el siglo XVIII.
( ) +
( ) +
( ) +
() = () +
!
!
!
()
( )
+
!
( )
( )
( )
()
()
() = () +
+
+
+
!
!
!
( )
+ ()
!
()
246
Ahora:
1.- La funcin () debe pertenecer al ser infinito esto quiere decir que tenga
infinitas derivadas.
2.- Que la serie converge (que por ms que crezca la serie o la alarguemos
hacia el infinito, la suma de todos sus elementos tiende a un lmite n).
Si en particular hacemos = y = + entonces la ecuacin cambiaria:
= , = , =
"" ""
( + ) = ( ) + ( )
()
()
()
()
+ ( )
+ ( )
+ + ( )
!
!
!
!
3.- Contando con una condicin inicial, Usaremos los primeros trminos de la
sucesin en serie para aproximar los valores de "" o ().
4.- Derivaremos la funcin, claro que no se puede derivar infinitas veces, pero
entre ms veces se derive ms aproximado ser el resultado
() = () +
()
() = () +
()
()
()
()
()
()
()
+
+
+ +
!
!
!
!
Ejemplos:
Usar las series de Taylor para hallar la solucin en serie de
= 2 . Donde
= () + () +
() ()
+
+
!
!
() =
() = =
= + ( )
() = + =
= +
() = + =
= + + ( )
() = + + =
() () () ()
+
+
+
!
!
!
!
= + + + +
+
Solucin:
= +
=1
248
= = ()() =
= + = ()() + =
()
.
= + (. ) +
= .
!
1. Cargar B:
Al cargarlo se crea automticamente un proyecto visual.
249
INTERFAZ GRAFICA:
Presentacin del programa, con dos botones uno para entrar a la ventana
principal y el otro para salir del programa.
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
Close();
}
//---------------------------------------------------------------------------
}
//---------------------------------------------------------------------------
Ventana principal.
Esta ventana consta de 27 componentes Edit de los cuales 17 estn ocultos para aparecer
cuando se cumplan ciertas condiciones del programa, con 7 botones, 3 de ellos para
calcular, 2 para leer datos y guardarlos, uno para regresar a la presentacin y uno para
borrar todos los datos.
Auxilindonos de los componentes RadioButton los cuales se corresponde una ecuacin
diferente dependiendo que se quiere calcular, si lo que se quiere calcular es la solucin
general de la ecuacin diferencial, la cual es otra ecuacin debemos dar las condiciones
iniciales y se marcara el RadioButton1 o bien si lo que se desea es saber la posicin de un
punto a una distancia de un punto conocido (0 , 0 ) en las condiciones iniciales
daremos el valor de .
252
253
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include "Unit3.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
#include <math.h>
double a, b, c, d, e, f, g, h, i, m, n;
255
TForm2 *Form2;
//--------------------------------------------------------------------------__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button2Click(TObject *Sender)
{
Close();
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button1Click(TObject *Sender)
{
Edit1->Text="";
Edit2->Text="";
Edit3->Text="";
Edit4->Text="";
Edit5->Text="";
Edit6->Text="";
Edit7->Text="";
Edit8->Text="";
Edit10->Text="";
Edit11->Text="";
RadioButton1->Checked=false;
RadioButton2->Checked=false;
256
Edit9->Visible=false;
Edit12->Visible=false;
Edit13->Visible=false;
Edit14->Visible=false;
Edit15->Visible=false;
Edit16->Visible=false;
Edit17->Visible=false;
Edit18->Visible=false;
Edit19->Visible=false;
Edit20->Visible=false;
Edit21->Visible=false;
Edit22->Visible=false;
Edit23->Visible=false;
Edit24->Visible=false;
Edit25->Visible=false;
Edit26->Visible=false;
Edit27->Visible=false;
Image5->Visible=false;
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button5Click(TObject *Sender)
{
if(Edit1->Text==""){
Edit1->Text="Sin dato";
}
if(Edit1->Text!="Sin dato"){
a=Edit1->Text.ToDouble();
}
257
if(Edit2->Text==""){
Edit2->Text="Sin dato";
}
if(Edit2->Text!="Sin dato"){
b=Edit2->Text.ToDouble();
}
if(Edit3->Text==""){
Edit3->Text="Sin dato";
}
if(Edit3->Text!="Sin dato"){
c=Edit3->Text.ToDouble();
}
if(Edit1->Text=="Sin dato" || Edit2->Text=="Sin dato"){
RadioButton1->Checked=false;
RadioButton2->Checked=false;
}
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button3Click(TObject *Sender)
258
{
if(RadioButton2->Checked==true){
m=b+(d*c)+(e*c*c/2)+(f*c*c*c/6)+(g*c*c*c*c/24);
Edit11->Text=AnsiString(m);
}
}
//---------------------------------------------------------------------------
if(Edit7->Text==""){
Edit7->Text="Falta derivada";
}
if(Edit7->Text!="Falta derivada"){
g=Edit7->Text.ToDouble();
}
if(Edit8->Text==""){
Edit8->Text="Falta derivada";
}
if(Edit8->Text!="Falta derivada"){
h=Edit8->Text.ToDouble();
}
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button6Click(TObject *Sender)
{
if(RadioButton1->Checked==true) {
Edit10->Text="Falta la variable h";
}
if(RadioButton2->Checked==true && Edit8->Text!="" && Edit8->Text!="Falta
derivada") {
n=h*c*c*c*c*c/120;
Edit10->Text=AnsiString(n);
}
if(RadioButton2->Checked==false || Edit8->Text=="" || Edit8->Text=="Falta
derivada"){
Edit10->Text="Falta algun dato";
}
260
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button8Click(TObject *Sender)
{
if(RadioButton1->Checked==true && Edit1->Text!="0"){
Edit9->Visible=true;
Edit12->Visible=true;
Edit13->Visible=true;
Edit14->Visible=true;
Edit15->Visible=true;
Edit16->Visible=true;
Edit17->Visible=true;
Edit18->Visible=true;
Edit19->Visible=true;
Edit20->Visible=true;
Edit21->Visible=true;
Edit9->Text=AnsiString(b);
Edit12->Text=AnsiString(d);
Edit13->Text=AnsiString(a);
Edit14->Text=AnsiString(e);
Edit15->Text=AnsiString(a);
Edit16->Text=AnsiString(f);
Edit17->Text=AnsiString(a);
Edit18->Text=AnsiString(g);
Edit19->Text=AnsiString(a);
Edit20->Text=AnsiString(h);
Edit21->Text=AnsiString(a);
}
261
Edit21->Text=AnsiString(a);
Edit22->Text=AnsiString(b);
Edit23->Text=AnsiString(d);
Edit24->Text=AnsiString(e);
Edit25->Text=AnsiString(f);
Edit26->Text=AnsiString(g);
Edit27->Text=AnsiString(h);
Image5->Visible=true;
}
263
12.
Lgica difusa
264
Cundo NO ES RECOMENDABLE?
No es recomendable utilizar la lgica difusa cuando algn modelo matemtico
ya soluciona eficientemente el problema, cuando los problemas son lineales o
cuando no tienen solucin
Botn Velocidad del Paso: calcula la velocidad con la que la persona debera
de caminar. Se calcula con la siguiente formula: velpaso=Edit3>Text.ToDouble()/tie;
Botn Reset: borra los datos escritos en el formulario y reinicia el programa.
PROGRAMACION PARA LOS BOTONES
Bton metros:
dis=Edit2->Text.ToDouble();
Image2->Visible=True;
if(dis<=15){
Image2->Picture->LoadFromFile("cerca.bmp");
Label4->Caption="Cercana";
}
if(dis>15&&dis<=50){
Image2->Picture->LoadFromFile("mediocerca.bmp");
Label4->Caption="Medio cerca";
}
if(dis>50&&dis<=80){
Image2->Picture->LoadFromFile("lejos.bmp");
Label4->Caption="Lejana";
}
if(dis>80){
Image2->Picture->LoadFromFile("muylejos.bmp");
Label4->Caption="muy Lejana";
}
l=1;
if(k==1&&l==1){
Button4->Enabled=true;
266
Button1->Enabled=true;
}
Botn Tiempo en Cruzar
tie=dis/(vel*1000/3600);
Label6->Caption=tie;
Label5->Visible=true;
Label8->Visible=true;
Edit3->Visible=true;
267
Timer1->Enabled=true;
Button6->Enabled=true;
Bton Reset
Image3->Left=30;
Image4->Top=10;
Edit1->Text="";
Edit2->Text="";
Edit3->Text="";
k=0;
l=0;
Button4->Enabled=false;
Button1->Enabled=false;
Label2->Caption="";
Label4->Caption="";
Label6->Caption="";
Label9->Caption="";
Label11->Caption="";
Label5->Visible=false;
Label8->Visible=false;
Edit3->Visible=false;
Image1->Visible=false;
Image2->Visible=false;
Timer1->Tag=0;
Button6->Enabled=false;
DE ESTA FORMA ES COMO SE PROGRAMARIA EN EL LENGUAJE C++.
268
13.
269
270
271
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
double x1, y1, x2, y2, Tol, n, aux=0, c1, c2, dx, dy,i;
TForm2 *Form2;
272
x1=Edit1->Text.ToDouble();
y1=Edit2->Text.ToDouble();
Tol=Edit3->Text.ToDouble();
n=Edit4->Text.ToDouble();
aux=0;
i=0;
if (x1==0||y1==0||Tol<=0||n<=0)
{
if (x1==0&&y1==0&&Tol<=0&&n<=0)
{
ShowMessage("x1 y y1 deben ser distintos de cero, la tolerancia y n
mayores que cero.");
Edit1->Text="";
Edit2->Text="";
Edit3->Text="";
Edit4->Text="";
Edit1->SetFocus();
}
else if (x1==0&&y1==0&&Tol<=0)
{
ShowMessage("x1 y y1 deben ser distintos de cero y la tolerancia
mayor que cero.");
Edit1->Text="";
Edit2->Text="";
Edit3->Text="";
273
Edit1->SetFocus();
}
else if (x1==0&&y1==0&&n<=0)
{
ShowMessage("x1 y y1 deben distintos de cero y n mayor que
cero.");
Edit1->Text="";
Edit2->Text="";
Edit4->Text="";
Edit1->SetFocus();
}
else if (y1==0&& Tol<=0&& n<=0)
{
ShowMessage("x1 debe ser distinto de cero, la tolerancia y n
mayores que cero.");
Edit2->Text="";
Edit3->Text="";
Edit4->Text="";
Edit2->SetFocus();
}
else if (x1==0&& Tol<=0&&n<=0)
{
ShowMessage("x1 debe ser distinto de cero, la tolerancia mayor que
cero y n mayor que 2.");
Edit1->Text="";
Edit3->Text="";
Edit4->Text="";
Edit1->SetFocus();
}
274
}
else if (y1==0&&n<=0)
{
ShowMessage("y1 debe ser distinto de cero y n mayor que cero.");
Edit2->Text="";
Edit4->Text="";
Edit2->SetFocus();
}
else if (Tol<=0&&n<=0)
{
ShowMessage("La tolerancia debe ser mayor que cero y n mayor que
cero.");
Edit3->Text="";
Edit4->Text="";
Edit3->SetFocus();
}
else if (x1==0)
{
ShowMessage("x1 debe distinto de cero.");
Edit1->Text="";
Edit1->SetFocus();
}
else if (y1==0)
{
ShowMessage("y1 debe distinto de cero.");
Edit2->Text="";
Edit2->SetFocus();
}
276
else if (Tol<=0)
{
ShowMessage("La Tolerancia debe ser mayor que cero");
Edit3->Text="";
Edit3->SetFocus();
}
else
{
ShowMessage("n debe ser mayor que cero.");
Edit4->Text="";
Edit4->SetFocus();
}
}
else
{
while(aux!=1&&i<n)
{
x2=(x1/2)+(11/(4*x1));
y2=(y1/2)+(9/(4*y1));
dx=abs(x2-x1);
dy=abs(y2-y1);
if (dx<Tol && dy<Tol)
{
Label11->Caption="Se encontr un valor menor a la tolerancia.";
aux=1;
}
else
277
{
Label11->Caption="No se encontr un valor menor a la tolerancia.
(Intente con un mayor nmero de iteraciones).";
}
x1=x2;
y1=y2;
i++;
}
c1=(x2*x2)+(y2*y2);
c2=(x2*x2)-(y2*y2);
Edit5->Text=AnsiString(x2);
Edit6->Text=AnsiString(y2);
Edit7->Text=AnsiString(c1);
Edit8->Text=AnsiString(c2);
Edit4->Text=AnsiString(i);
}
}
if (aux<=1)
{
x1=Edit1->Text.ToDouble();
y1=Edit2->Text.ToDouble();
278
Tol=Edit3->Text.ToDouble();
i=0;
}
if (x1==0||y1==0||Tol<=0)
{
if (x1==0&&y1==0&&Tol<=0)
{
ShowMessage("x1 y y1 deben ser distintos de cero y la tolerancia
mayor que cero.");
Edit1->Text="";
Edit2->Text="";
Edit3->Text="";
Edit1->SetFocus();
}
else if (x1==0&& y1==0)
{
ShowMessage("x1 y y1 deben ser distintos de cero.");
Edit1->Text="";
Edit2->Text="";
Edit1->SetFocus();
}
else if (x1==0&& Tol<=0)
{
ShowMessage("x1 debe ser distinto de cero y la tolerancia mayor que
cero");
Edit1->Text="";
Edit3->Text="";
Edit1->SetFocus();
}
279
{
x2=(x1/2)+(11/(4*x1));
y2=(y1/2)+(9/(4*y1));
dx=abs(x2-x1);
dy=abs(y2-y1);
if (dx<Tol && dy<Tol)
{
Label11->Caption="Se encontr un valor menor a la tolerancia.";
}
else
{
Label11->Caption="No se encontr un valor menor a la tolerancia.
(Intente con un mayor nmero de iteraciones).";
}
x1=x2;
y1=y2;
c1=(x2*x2)+(y2*y2);
c2=(x2*x2)-(y2*y2);
aux=aux+2;
i++;
Edit5->Text=AnsiString(x2);
Edit6->Text=AnsiString(y2);
Edit7->Text=AnsiString(c1);
Edit8->Text=AnsiString(c2);
Edit4->Text=AnsiString(i);
}
}
281
Edit1->Text="";
Edit2->Text="";
Edit3->Text="";
Edit4->Text="";
Edit5->Text="";
Edit6->Text="";
Edit7->Text="";
Edit8->Text="";
Edit1->SetFocus();
Label11->Caption="";
aux=0;
282
14.
( , ) =
( , ) + (+1 , +1 )
2
+1 = + ( , )
( , ) =
( , ) + (+1 , + ( , ) )
2
Euler mejorado
Euler sin
mejorar
Euler modificado
2
283
+1 = +
( , ) + (+1 , + ( , ) )
2
Considrese
1 = ( , )
2 = (+1 , + ( , ) ) = (+1 , + 1 )
1 + 2
2
Ejemplo:
+ 4 = 2
= 0.1
(0) = 1
Poner en la forma () = (, )
= 2 4
+1 = +
1 + 2
2
1 = ( , )
1 = ( 2 4 )
2 = (+1 , + 1)
2 = ( 2+1 4( + 1))
1 = 1 +
0.30.21296
2
= 0.74352
284
Programacin
Interfaz grfica propuesta
Botn Graficar:
Realiza una grfica de la funcin con los puntos calculados sobre un eje
coordenado.
Botn Reset:
Borra los datos escritos en el formulario y posiciona el puntero en el primer Edit.
285
Cdigo de Programacin
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//----------------------------------------------------------------------------------bariables
#pragma package(smart_init)
#pragma resource "*.dfm"
#include <math.h>
TForm1 *Form1;
//--------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------void __fastcall TForm1::Button1Click(TObject *Sender)
{
Close();
}
//--------------------------------------------------------------------------286
for(k=1;k<=10;k++)
{
X[k]=X[k-1]+h;
k1=h*((exp(-2*X[k-1]))-(4*Y[k-1]));
k2=h*((exp(-2*X[k]))-(4*(Y[k-1]+k1)));
Y[k]=Y[k-1]+((k1+k2)/2);}
Edit4->Text=AnsiString(X[1]);
Edit5->Text=AnsiString(X[2]);
Edit6->Text=AnsiString(X[3]);
Edit7->Text=AnsiString(X[4]);
Edit8->Text=AnsiString(X[5]);
Edit9->Text=AnsiString(X[6]);
Edit10->Text=AnsiString(X[7]);
Edit11->Text=AnsiString(X[8]);
Edit12->Text=AnsiString(X[9]);
Edit13->Text=AnsiString(X[10]);
Edit14->Text=AnsiString(Y[1]);
Edit15->Text=AnsiString(Y[2]);
Edit16->Text=AnsiString(Y[3]);
Edit17->Text=AnsiString(Y[4]);
Edit18->Text=AnsiString(Y[5]);
Edit19->Text=AnsiString(Y[6]);
Edit20->Text=AnsiString(Y[7]);
Edit21->Text=AnsiString(Y[8]);
Edit22->Text=AnsiString(Y[9]);
287
Edit23->Text=AnsiString(Y[10]);
}
Canvas->PenPos=TPoint(256,382);
Canvas->LineTo(864,382);
Canvas->Pen->Width=2;
Canvas->PenPos=TPoint(268,116);
Canvas->LineTo(272,112);
Canvas->LineTo(276,116);
Canvas->PenPos=TPoint(860,378);
Canvas->LineTo(864,382);
Canvas->LineTo(860,386);
Canvas->Pen->Color=0x00C08080;
Canvas->Pen->Width=2;
Canvas->PenPos=TPoint(272+X[0]*150,382-(Y[0])*150);
for(k=1; k<=10;k++)
{
Canvas->LineTo(272+X[k]*150,382-(Y[k])*150);
}
}
//--------------------------------------------------------------------------void __fastcall TForm1::Button4Click(TObject *Sender)
{
288
x=0;
y=0;
Edit1->Text="";
Edit2->Text="";
Edit3->Text="";
Edit4->Text="";
------------------Button(reset)
Edit5->Text="";
Edit6->Text="";
Edit7->Text="";
Edit8->Text="";
Edit9->Text="";
Edit10->Text="";
Edit11->Text="";
Edit12->Text="";
Edit13->Text="";
Edit14->Text="";
Edit15->Text="";
Edit16->Text="";
Edit17->Text="";
Edit18->Text="";
Edit19->Text="";
Edit20->Text="";
Edit21->Text="";
Edit22->Text="";
Edit23->Text="";
Edit1->SetFocus();
Form1->Visible=false;
Form1->Visible=true;
}
//--------------------------------------------------------------------------289
15.
Lgica Difusa
orden que es relativa, por lo tanto si se emplea una unidad difusa, hay que
tener bien claro el contexto donde se est utilizando para as encontrar un
punto de referencia y una unidad de medida. En ocasiones, enunciados difusos
indican unidades relativas y subunidades ms no unidades absolutas.
La aplicacin de la lgica difusa es necesaria para los conjuntos complejos
donde no existe una solucin simple o modelo matemtico a seguir, de igual
manera se podr utilizar aplicar para sistemas que no pueden medir de forma
confiable y que en su paso de ajustar una variable desajusta otra.
Desventajas:
No se aplica para modelos matemticos eficientes de un problema.
Cuando los problemas sean de manera lineal.
Cuando un problema cuenta con un solucin satisfactoria.
Ventajas:
Controla sistemas complejos.
Permite trabajar con informacin no exacta.
Define evaluaciones convencionales.
Permite la utilizacin de conocimientos ambiguos o imprecisos.
Aplicaciones de la lgica difusa en la vida:
Despus del desarrollo de la lgica difusa su aplicacin se expandi a distintos
mbitos de nuestra vida como son los siguientes:
291
{ A = (x, pA(x)) | x P }
Donde pA(x) es la funcin de perteneca de la variable x, y P es el universo en
discurso. Cuando ms cerca este la pertenencia del conjunto A al valor 1,
mayor ser la perteneca de la variable x al conjunto A. por ejemplos:
Controlador Difuso
292
Por otro lado cabe recalcar que la lgica difusa se aplica en sistemas de
control difuso para formular reglas que controlen un sistema, es decir, que
tienen la capacidad de tomar decisiones sobre ciertas acciones que representa
su funcionamiento, para ello se basa de sencillos paso de ordenamiento como
se muestra a continuacin:
Fusificacin
En relacin con la lgica clsica nos damos cuenta que existen muchas
inferencia entre la lgica difusa que son variables indispensables y de gran
importancia, as mismo denotamos que la lgica difusa son procedimientos
entre ellas no son de intuitivos sino que estn estrechados por variables y
patrones de orden para su funcionamiento. De esta manera se recomienda
hacer uso de este procedimiento cuando tengamos trminos indefinidos de
acciones que den un resultado, o cuando necesitemos condicionantes que
realizar una actividad para el cuidado de otro orden.
NUESTRAS PROGRAMACONES
Como el primer programa que desarrollamos no aplicaba a la ingeniera civil
decidimos hacer otra alternativa, pero debido a la falta de tiempo, esta ya no se
pudo terminar bien sin embargo, es capaz de dar un ejemplo de la aplicacin
de la lgica difusa en ingeniera civil
1.1. INTERFAZ 1
294
Formulario 1
Paso 1: se insert en el formulario 1, tres componentes image para cambiar
el fondo de la interfaz.
Paso 2: se insertar nueve componentes Label, esto para los datos como el
295
Label 7:
S.
Label 2:
Label 8:
Metros
Label 9:
Label 4:
Label 11:
Label 6:
Paso 7: se insertaron 3 componentes Edit, y en la propiedad Text se borr
la palabra Edit
Paso 8: Se insert un componente Shape y se le cambio el color a azul
celeste, este ser nuestro rio por donde navegara nuestro barco.
Paso 9: Se insert 1 componente timer
Paso 10: Se insert 6 componentes Button, y en la propiedad Caption se
les cambio el nombre por:
2) Button 2: km/h
3) Button 3: metros
4) Button 4: Tiempo en cruzar
5) Button 5: Reiniciar
6) Button 6: Regresar
//--------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
296
#include "Unit2.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
Form2->Show();
}
//--------------------------------------------------------------------------void __fastcall TForm1::Button2Click(TObject *Sender)
{
Salir
Close();
}
//---------------------------------------------------------------------------
297
Donde las funciones de los Button son nicamente para entrar a la siguiente
interfaz y para cerrar el programa.
1.1. INTERFAZ 2
298
Cdigo de programacin.
//--------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
double vel,dis, tie, velpaso;
int k, l, y;
TForm2 *Form2;
//---------------------------------------------------------------------------
vel=Edit1->Text.ToDouble();
Image1->Visible=True;
if(vel<=30){
Image1->Picture->LoadFromFile("lento.jpg");
Label2->Caption="Lenta";
299
}
if(vel>30&&vel<=60){
Km/h
Image1->Picture->LoadFromFile("medio.jpg");
Label2->Caption="Media";
}
if(vel>60){
Image1->Picture->LoadFromFile("rapido.jpg");
Label2->Caption="Rapida";
}
k=1;
if(k==1&&l==1){
Button4->Enabled=true;
Button1->Enabled=true;
}
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button3Click(TObject *Sender)
{
dis=Edit2->Text.ToDouble();
Image2->Visible=True;
if(dis<=15){
Image2->Picture->LoadFromFile("cerca.jpg");
Label4->Caption="Cercana";
}
300
if(dis>15&&dis<=50){
Image2->Picture->LoadFromFile("medio cerca.jpg");
metros
Label4->Caption="Medio cerca";
}
if(dis>50&&dis<=80){
Image2->Picture->LoadFromFile("lejos.jpg");
Label4->Caption="Lejana";
}
if(dis>80){
Image2->Picture->LoadFromFile("muy lejos.jpg");
Label4->Caption="muy Lejana";
}
l=1;
if(k==1&&l==1){
Button4->Enabled=true;
Button1->Enabled=true;
}
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button4Click(TObject *Sender)
{
tie=dis/(vel*1000/3600);
Label6->Caption=tie;
Tiempo en cruzar
Label5->Visible=true;
Label8->Visible=true;
301
Edit3->Visible=true;
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button1Click(TObject *Sender)
{
velpaso=Edit3->Text.ToDouble()/tie;
Velocidad de paso
Label9->Caption=velpaso;
if(velpaso<=.5){
Label11->Caption="La persona puede pasar nadando muy despacio ";
}
if(velpaso>.5&&velpaso<=1){
Label11->Caption="La persona puede pasar nadando despacio ";
}
if(velpaso>1&&velpaso<=1.5){
Label11->Caption="La persona puede pasar nadando normal ";
}
if(velpaso>1.5&&velpaso<=2){
Label11->Caption="La persona puede pasar rapido ";
}
if(velpaso>2){
Label11->Caption="La persona no puede pasar ";
}
Timer1->Enabled=true;
}
//--------------------------------------------------------------------------302
{
Timer1->Tag=Timer1->Tag+1;
if(Timer1->Tag>=tie*10)
Componente Timer
{
Timer1->Enabled=false;
}
Image3->Left=50+Timer1->Tag*(770/(10*tie));
if(velpaso>2){
}
else
{
Image4->Top=300+Timer1->Tag*(250/(10*tie));
}
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button5Click(TObject *Sender)
{
Image3->Left=50;
Image4->Top=300;
Reiniciar
Edit1->Text="";
Edit2->Text="";
Edit3->Text="";
k=0;
303
l=0;
Button4->Enabled=false;
Button1->Enabled=false;
Label2->Caption="";
Label4->Caption="";
Label6->Caption="";
Label9->Caption="";
Label11->Caption="";
Label5->Visible=false;
Label8->Visible=false;
Edit3->Visible=false;
Image1->Visible=false;
Image2->Visible=false;
Timer1->Tag=0;
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button7Click(TObject *Sender)
{
Regresar
Close();
}
//---------------------------------------------------------------------------
304
2.1. INTERFAZ 1
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Unit2.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------------__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
305
Form2->Show();
}
//--------------------------------------------------------------------------void __fastcall TForm1::Button2Click(TObject *Sender)
{
Salir
Close();
}
//---------------------------------------------------------------------------
2.2. Interfaz 2
306
//--------------------------------------------------------------------------#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include "Unit3.h"
//--------------------------------------------------------------------------#pragma package(smart_init)
#pragma resource "*.dfm"
double vol,anc,pas, tie, cantpaso, alt;
int k, l, y;
TForm2 *Form2;
//--------------------------------------------------------------------------__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button2Click(TObject *Sender)
{
307
vol=Edit1->Text.ToDouble();
if(vol<=1000)
{
M3
Label2->Caption="MINIMA";
}
if(vol>1000&&vol<=6000){
Label2->Caption="CONSIDERABLE";
}
if(vol>6000){
Label2->Caption="ABUNDANTE";
}
k=1;
if(k==1&&l==1){
Button4->Enabled=true;
Button1->Enabled=true;
}
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button3Click(TObject *Sender)
{
anc=Edit2->Text.ToDouble();
if(anc<=150){
Label4->Caption="PEQUEA";
}
if(anc>150&&anc<=500){
Label4->Caption="MEDIANA";
}
Anchura de la presa.
308
if(anc>500&&anc<=800){
Label4->Caption="GRANDE";
}
if(anc>800){
Label4->Caption="NI EN TUS SUEOS";
}
l=1;
if(k==1&&l==1){
Button4->Enabled=true;
Button1->Enabled=true;
}
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button4Click(TObject *Sender)
{
pas=vol/anc*10/3600;
Tiempo de paso
Label6->Caption=tie;
Label6->Caption=AnsiString(pas);
Label5->Visible=true;
Label8->Visible=true;
Edit3->Visible=true;
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button1Click(TObject *Sender)
{
alt=Edit3->Text.ToDouble();
309
cantpaso=alt/pas;
Label9->Caption=AnsiString(cantpaso);
if(cantpaso<=100){
Label11->Caption="Flujo ptima de paso";
}
Velocidad de paso
if(cantpaso>100&&cantpaso<=200){
Label11->Caption="Flujo controlado ";
}
if(cantpaso>200&&cantpaso<=350){
Label11->Caption=" Flujo moderado ";
}
if(cantpaso>350&&cantpaso<=600){
Label11->Caption="Flujo mximo ";
}
if(cantpaso>600){
Label11->Caption="Flujo excesivo descontrolado ";
}
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button5Click(TObject *Sender)
{
Edit1->Text="";
Edit2->Text="";
Edit3->Text="";
k=0;
l=0;
Button4->Enabled=false;
Button1->Enabled=false;
Reset
310
Label2->Caption="";
Label4->Caption="";
Label6->Caption="";
Label9->Caption="";
Label11->Caption="";
Label5->Visible=false;
Label8->Visible=false;
Edit3->Visible=false;
}
//--------------------------------------------------------------------------void __fastcall TForm2::Button7Click(TObject *Sender)
{
Regresar
Close();
}
//----------------------------------------------------------------
311