ClubEnsayos.com - Ensayos de Calidad, Tareas y Monografias
Buscar

METODOS NUMERICOS EN C++

ARMANDO GARCÍA ARAIZATrabajo3 de Abril de 2019

8.736 Palabras (35 Páginas)165 Visitas

Página 1 de 35

//RUNGE-KUTTA

#include

#include

#include

using namespace std;

class Runge

{

      private:

                float Y[5];

      public:

             Runge(){};

             void calcularonge();

};

void Runge::calcularonge()

{    float h=0.1;

         float K1[5]={0};

         float K2[5]={0};

         float K3[5]={0};

         float K4[5]={0};

     Y[0]=1;

     float X[5];

     X[0]=0.5;

     X[1]=0.6;

     X[2]=0.7;

     X[3]=0.8;

     X[4]=0.9;

     X[5]=1.0;

         cout<<"Ingresa el valor de h"<

         cin>>l;

         for(int i=0; i<5; i++)

         {

                 K1[i]=(0.1)*(X[i]+2*(X[i])*(Y[i]));

                 K2[i]=(0.1)*((X[i]+((0.1)/2))+2*(X[i]+((0.1)/2))*(Y[i]+(K1[i]/2)));

                 K3[i]=(0.1)*((X[i]+((0.1)/2))+2*(X[i]+((0.1)/2))*(Y[i]+(K2[i]/2)));

                 K4[i]=(0.1)*((X[i]+(0.1))+2*(X[i]+(0.1))*(Y[i]+K3[i]));

                 Y[i+1]=Y[i]+((0.16666666666667)*(K1[i]+(2*K2[i])+(2*K3[i])+K4[i]));

                  }  

           cout<<"K1"<<"   "<<"\tK2"<<"   "<<"\t\tK3"<<"   "<<"\t\t\tK4"<

        for(int i=0; i<5; i++)

        {

                cout<

        }

        cout<

        cout<<"X"<<"\t\tY(x)"<

        for(int i=0; i<6; i++)

        {

                cout<

        }

}

int main()

{  

        Runge obj;

                cout<<"\t\tMetodo de Runge-Kutta"<

        cout<<"Dada la ecuacion: y´=x+2xy \ncondiciones iniciales y(0.5)=1"<

        "en el intervalo 0.5>=X<=1.0 de cuarto orden"<

    obj.calcularonge();

    system("PAUSE");

    return 0;

}

//GAUSS SEIDEL
#include

#include

#include

#include

#include

#include

using namespace std;

class gauss

{

      private:

              float a1,b1,c1,d1,a2,b2,c2,d2,a3,b3,c3,d3;

              float x1,x2,x3,ERA1,ERA2,ERA3,x1a,x1aa,x2a,x2aa,x3a,x3aa;

             

      public:

                         void portada ();

             void pedirpoli ();

             float condicion ();

             void mostrar ();

             float e1();

             float e2();

             float e3();

             void primercalculo();

             void calculopoli ();          

             void imprime ();

};

void gauss::pedirpoli()

{     cout<<" ax1 + bx2 + cx3 = d .....(1)"<

     //cout<<"Se debe introducir una matriz diagonalmente dominante"<

     cout<<"a=";

     cin>>a1;

     cout<<"b=";

     cin>>b1;

     cout<<"c=";

     cin>>c1;

     cout<<"d=";

     cin>>d1;

     system("cls");

     cout<<" ax1 + bx2 + cx3 = d ....(2)"<

     cout<<"a=";

     cin>>a2;

     cout<<"b=";

     cin>>b2;

     cout<<"c=";

     cin>>c2;

     cout<<"d=";

     cin>>d2;

     system("cls");

     cout<<" ax1 + bx2 + cx3 = d ....(3)"<

     cout<<"a=";

     cin>>a3;

     cout<<"b=";

     cin>>b3;

     cout<<"c=";

     cin>>c3;

     cout<<"d=";

     cin>>d3;

     system("cls");

}

void gauss::primercalculo ()

{

x1=d1/a1;

x2=(d2-(a2*x1))/b2;

x3=(d3-(a3*x1)-(b3*x2))/c3;

ERA1=0;

ERA2=0;

ERA3=0;

cout<

void gauss::calculopoli ()

{

x1aa=x1;

x2aa=x2;

x3aa=x3;

x1=(d1-(c1*x3)-(b1*x2))/a1;

x2=(d2-(a2*x1)-(c2*x3))/b2;

x3=(d3-(a3*x1)-(b3*x2))/c3;

x1a=x1;

x2a=x2;

x3a=x3;

}

void gauss::imprime ()

{cout<

float gauss::condicion ()

{float r=1, t=2, x1=a1, x2=a2, x3=a3, y1=b1, y2=b2, y3=b3, z1=c1, z2=c2, z3=c3 ;

if(1<0)

x1=x1*(-1);

if(x2<0)

x2=x2*(-1);

if(x3<0)

x3=x3*(-1);

if(y1<0)

y1=y1*(-1);

if(y2<0)

y2=y2*(-1);

if(y3<0)

y3=y3*(-1);

if(z1<0)

z1=z1*(-1);

if(z2<0)

z2=z2*(-1);

if(z3<0)

z3=z3*(-1);

if (x1

{cout<<"La matriz no es diagonalmente dominante, verificar";
return r;}

if (y2

{cout<<"La matriz no es diagonalmente dominante, verificar";

return r;}

if (z3

{cout<<"La matriz no es diagonalmente dominante, verificar";

return r;}

return t;}

void gauss::mostrar()

{

cout<<"Matriz Ingresada"<

cout<

cout<

cout<

system("pause");

system("cls");}

float gauss::e1()

{ERA1=((x1a-x1aa)/x1a)*100;

if(ERA1<0)

{ERA1=ERA1*(-1);}

return ERA1;}

float gauss::e2()

{ERA2=((x2a-x2aa)/x2a)*100;

if(ERA2<0)

{ERA2=ERA2*(-1);}

return ERA2;

}

float gauss::e3()

{

ERA3=((x3a-x3aa)/x3a)*100;

if(ERA3<0)

{ERA3=ERA3*(-1);

}

return ERA3;

}

int main ()

{float q,error,E1,E2,E3;

        int n,u=0;

        gauss A;

        A.pedirpoli ();

        q=A.condicion ();

        n=q;

        switch (n)

        {

        case 1:

{break;

}case 2:

{A.mostrar();

cout<<"Introduzca el error minimo"<

cin>>error;

system("cls")
A.primercalculo();

A.imprime ();
 do{
A.calculopoli ();

 E1=A.e1();

 E2=A.e2();
E3=A.e3();
A.imprime ();

 u=u+1;
 if(E1  {break;

}}while(u<20);

} };

getch ();}

-----------------------------------------------------------------------------------------------------------------------------------

//ROMBERG
# include

# include

# include

# include

# include

   using namespace std;

  class romberg {

            private:

                    float h, a, b, X[40], Y[40], fun, It, I1, I2, I3, I4, suma;

...

Descargar como (para miembros actualizados) txt (33 Kb) pdf (95 Kb) docx (25 Kb)
Leer 34 páginas más »
Disponible sólo en Clubensayos.com