METODOS NUMERICOS EN C++
Enviado por ARMANDO GARCÍA ARAIZA • 3 de Abril de 2019 • Trabajo • 8.736 Palabras (35 Páginas) • 129 Visitas
//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)
...