Está en la página 1de 23

//PROGRAMA NUMERO 1: PROMEDIO

//DANIEL MEMIJE GARDUO


#include<conio.h>
#include<iostream>
using namespace std;
//funcion principal
void main()
{
int n, i;
float sum, x[50], prom;
cout << "\n
PROGRAMA NUMERO 1: PROMEDIO \n";
//aqui se introducen los datos
cout << "\nCuatos datos promediaras? = "; cin >> n;
sum = 0;
for (i = 1; i <= n; i++)
{
cout << "\nIntroduce el valor de x[" << i << "]= "; cin >> x[i];
sum = sum + x[i];
}
//en esta parte se calcula el promedio y se imprime el resultado
prom = sum / n;
cout << "\n\nEl promedio es= " << prom;
//pausa del sistema
_getch();
}

//PROGRAMA NUMERO 2: PROMEDIO USANDO LAS FUNCIONES "leevect () y prom


()"
//DANIEL MEMIJE GARDUO
#include<conio.h>
#include<iostream>
using namespace std;
//prototipos de funcion
void leevect(int, float[50], char[5]);
float prom(int, float[50]);
//funcion principal
void main()
{
int n, i;
float sum, x[50], p;
cout << "\n
PROGRAMA NUMERO 2: PROMEDIO USANDO LAS FUNCIONES
leevect() y prom() \n";
//aqui se introducen los datos
cout << "\nCuatos datos promediaras? = "; cin >> n;
//llamado de las funciones
leevect(n, x, "x");
p = prom (n, x);
//impresion en pantalla del promedio de los datos
cout << "\n\nEl promedio es= " << p;
//pausa del sistema
_getch();
}
//*******************aqui se definen las funciones**********************
void leevect(int n, float x[50], char nom[5])
{
int i;
for (i = 1; i <= n; i++)
{
cout << nom << "\nIntroduce el valor de x[" << i << "]= "; cin >>
x[i];
}
}
float prom(int n, float x[50])
{
int i;
float sum=0;
for (i = 1; i <= n; i++)
sum = sum + x[i];
return (sum / n);
}

//PROGRAMA NUMERO 3: MAYOR Y MENOR


//DANIEL MEMIJE GARDUO
#include<conio.h>
#include<iostream>
using namespace std;
//prototipos de funcion
void leevect(int, float[50], char[5]);
//funcion principal
void main()
{
int n, i;
float xme, xma, x[50];
cout << "\n
PROGRAMA NUMERO 3: MAYOR Y MENOR) \n";
//aqui se introducen los datos
cout << "\nCuatos datos promediaras? = "; cin >> n;
leevect(n, x, "y");
//Aqui se selecciona el mayor y el menor de los datos introducidos
xme = x[1];
xma = x[1];
for (i = 2; i <= n; i++)
{
if (x[i] < xma)
xme = x[i];
else
{
if (x[i] > xma)
xma = x[i];
}
}
//impresion en pantalla del promedio de los datos
cout << "\n\nEl mayor es= " << xma;
cout << "\n\nEl menor es= " << xme;
//pausa del sistema
_getch();
}
//*******************aqui se definen las funciones**********************
void leevect(int n, float x[50], char nom[5])
{
int i;
for (i = 1; i <= n; i++)
{
cout << nom << "\n Introduce el valor de x[" << i << "]= "; cin >>
x[i];
}
}

//PROGRAMA NUMERO 4: MAYOR Y MENOR con funcion que calcula el mayor y el


menor
//DANIEL MEMIJE GARDUO
#include<conio.h>
#include<iostream>
using namespace std;
//prototipos de funcion
void leevect(int, float[50], char[5]);
void mayme(int, float [50],float*, float*);
//funcion principal
void main()
{
int n, i;
float xme, xma, x[50];
cout << "\n
//PROGRAMA NUMERO 4: MAYOR Y MENOR con funcion que
calcula el mayor y el menor \n";
//aqui se introducen los datos
cout << "\nCuatos datos promediaras? = "; cin >> n;
leevect(n, x, "y");
//Aqui se llama a la uncion para encontrar el mayor y el menor de los datos
introducidos
mayme(n, x, &xma, &xme);
//impresion en pantalla del promedio de los datos
cout << "\n\nEl mayor es= " << xma;
cout << "\n\nEl menor es= " << xme;
//pausa del sistema
_getch();
}
//*******************aqui se definen las funciones**********************
void leevect(int n, float x[50], char nom[5])
{
int i;
for (i = 1; i <= n; i++)
{
cout << nom << "\n Introduce el valor de x[" << i << "]= "; cin >>
x[i];
}
}
void mayme(int n, float x[50], float*xma, float*xme)
{
int i;
*xme = x[1];
*xma = x[1];
for (i = 2; i <= n; i++)
{

if (x[i] < *xma)


*xme = x[i];
else
{
if (x[i] > *xma)
*xma = x[i];
}
}
}

//PROGRAMA NUMERO 5: ORDENAR LISTA DE NUMEROS


//DANIEL MEMIJE GARDUO
#include<conio.h>
#include<iostream>
using namespace std;
//prototipos de funcion
void leevect(int, float[50], char[5]);
void escribevect(int, float[50], char[5]);
//funcion principal
void main()
{
int n, i,pos,j;
float xme, aux, x[50];
cout << "\n
PROGRAMA NUMERO 5: ORDENAR LISTA DE NUMEROS \n";
//aqui se introducen los datos
cout << "\nCuatos datos introduciras? = "; cin >> n;
leevect(n, x, "dato");
//Aqui se llama a la uncion para encontrar el mayor y el menor de los datos
introducidos
for (i = 1; i <= n; i++)
{
xme = x[i];
pos = i;
//En este for es donde se ordenan los datos, del menor al mayor
for (j = i + 1; j <= n; j++)
{
if (x[j] < xme)
{
xme = x[j];
pos = j;
}
}

//aqui se intercambian los datos de posicion


aux = x[i];
x[i] = x[pos];
x[pos] = aux;

//en esta seccion se llama a la funcion para que escriba el vector ya


ordenado
escribevect(n, x, "dato");
_getch();
}
//*******************aqui se definen las funciones**********************
void leevect(int n, float x[50], char nom[5])
{
int i;

for (i = 1; i <= n; i++)


{
cout <<"\n"<< nom << " Introduce el valor de x[" << i << "]= "; cin
>> x[i];
}
}
void escribevect(int n, float x[50], char nom[5])
{
int i;
for (i = 1; i <= n; i++)
cout << "\n" << nom << "[" << i << "]= " << x[i];
}

//PROGRAMA NUMERO 6: METODO BISECCION


//DANIEL MEMIJE GARDUO
#include<conio.h>
#include<iostream>
#include<math.h>
//Definicion de la funcion con la que se trabajara
#define f1(x)(4.0*pow(x,3)-30.0*pow(x,2)+70.0*x-50)
using namespace std;
//funcion que calcula una raiz por el metodo de biseccion
double bi(int, float, float, float);
void main()
{
int nit, i;
float xu, xl,ep;
//Resultado con doble precisin para evitar errores por redondeo
double RAIZ;
cout << "\n

PROGRAMA NUMERO 6: METODO BISECCION \n";

//Aqui se introducen los limites


cout << "\nDame a xl= "; cin >> xl;
cout << "\nDame a xu= "; cin >> xu;
//limite de iteraciones
nit = 50;
//Error relativo minimo requerido
ep = 1e-4;

if (f1(xu)*f1(xl) < 0)
{
RAIZ = bi(nit, xu, xl, ep);
cout << "\n\nLa raiz es= " << RAIZ;
_getch();
}
else
cout << "\n\nNo existe raiz impar en el intervalo!!";
_getch();

//*******************aqui se definen las funciones**********************


double bi(int n, float xu, float xl, float ep)
{
int i,con=0;
double test,xr=0;
float aux, er;
for (i = 1; i <= n; i++)
{

aux = xr;
xr = (xu + xl) / 2;
test = f1(xr)*f1(xl);
if (xr == 0)
{
con = 1;
break;
}
if (test > 0)
xl = xr;
else
xu = xr;
if (i == 1)
er = 100;
else
er = abs((xr - aux) / xr) * 100;
if (er <= ep)
{
con = 1;
break;
}
cout << "\n" << xl <<" "<<xr<< "
}
if (con == 0)
deseado";

"<<er;

cout << "\n\nEl sistema no alacanzo el minimo de error

else

return xr;
}

" << xu<<"

cout << "\n\n EL SISTEMA CONVERGE!! ";

//PROGRAMA NUMERO 7: METODO FALSA POSICION


//DANIEL MEMIJE GARDUO
#include<conio.h>
#include<iostream>
#include<math.h>
//Definicion de la funcion con la que se trabajara
#define f1(x)(4.0*pow(x,3)-30.0*pow(x,2)+70*x-50)
//funcion que calcula una raiz por el metodo de FALSA POSICION
void falsi(int, float, float, float);
using namespace std;
void main()
{
int n=50,con;
float x1, x2,ep;
ep = 1E-4;
cout << "\n
PROGRAMA NUMERO 7: METODO FALSA POSICION \n";
//Aqui se introducen los limites
cout << "Dame a x1= "; cin >> x1;
cout << "Dame a x2= "; cin >> x2;
//llamado de la funcion para calcular la raiz
falsi(n, x1, x2, ep);
_getch();
}
//*******************aqui se definen las funciones**********************
void falsi(int n, float x1, float x2, float ep)
{
double xr, aux,er,test;
int i,con=0;
xr = 0;
for (i = 1; i <= n; i++)
{
aux = xr;
xr = x2 + (f1(x2)*(x2 - x1)) / (f1(x1) - f1(x2));
test = f1(xr);
if ( test== 0)
er = 0;
else
{
if (f1(x2)*f1(xr) > 0)
x2 = xr;
else
x1 = xr;
if (i == 1)
er = 100;
else
er = abs(xr - aux) / xr * 100;

}
cout << " " << x1 << "
if (er < ep)
{
con = 1;
break;
}

" << xr << "

" << x2 << "

"<<er<<"\n";

}
if (con = 1)
cout << "\nEl sistema converge!!! LA RAZIS ES= " << xr;
else
cout << "\El sistema _NO! converge";

//PROGRAMA NUMERO 8: METODO NEWTON RAPHSON


//DANIEL MEMIJE GARDUO
#include<iostream>
#include<math.h>
#include<conio.h>
//Definicion de la funcion y su derivada
#define f(x) (exp(-x)-x)
#define fp(x) (-exp(-x)-1)
using namespace std;
//funcion que calcula una raiz por el metodo de NEWTON RAPHSON
void newtonrapson(int, float, float);
void main()
{
int n, con;
float xr, es;
n = 40;
es = 1e-4;
cout << "\n

PROGRAMA NUMERO 8: METODO NEWTON RAPHSON \n";

//aqui se introduce el valor inicial para estimar la raiz


cout << "Dame el valor inicial= "; cin >> xr;
//llamado de la funcion para implementar el metodo
newtonrapson(n, es, xr);

_getch();

//*******************aqui se definen las funciones**********************


void newtonrapson(int n, float es, float xo)
{
int i, con;
float xr, er, aux;
er = 100;
xr = xo;
cout << "" << xr;
for (i = 1; i <= n; i++)
{
aux = xr;
xr = xr - f(xr)/(fp(xr));
if (xr != 0)
er = abs((xr - aux) / xr) * 100;
else
{
con = 1;
break;
cout << "\n " << xr << " 0% error

";

}
cout << "\n " << xr << "
if (er <= es)
{
con = 1;
break;
}

" << er;

}
if (con == 1)
cout << "\n\nEl programa converge!! LA RAIZ ES= "<<xr;
else
cout << "\n\nEl programa NO CONVERGE!!";

//PROGRAMA NUMERO 9: METODO TANGENTE


//DANIEL MEMIJE GARDUO
#include<iostream>
#include<math.h>
#include<conio.h>
//Definicion de la funcion
#define f(x) (exp(-x)-x)
using namespace std;
//funcion que calcula una raiz por el metodo de TANGENTE
void tangente(int, float, float);
void main()
{
int n, con;
float xr, es;
n = 40;
es = 1e-4;
cout << "\n

PROGRAMA NUMERO 9: METODO TANGENTE \n";

//aqui se introduce el valor inicial para estimar la raiz


cout << "Dame el valor inicial= "; cin >> xr;
//llamado de la funcion para implementar el metodo
tangente(n, es, xr);
_getch();
}
//*******************aqui se definen las funciones**********************
void tangente(int n, float es, float xo)
{
int i, con;
float xr, er, aux;
er = 100;
xr = xo;
cout << "" << xr;
for (i = 1; i <= n; i++)
{
aux = xr;
//APROXIMACION DE LA DERIVADA POR MEDIO DE UNA DIFERENCIA
DIVIDIDA
//HACIA ADELANTE
xr = xr - (.001*xr*f(xr)/(f(xr+.001)-f(xr)));
if (xr != 0)
er = abs((xr - aux) / xr) * 100;
else
{
con = 1;

break;
cout << "\n " << xr << " 0% error

}
cout << "\n " << xr << "
if (er <= es)
{
con = 1;
break;
}

";

" << er;

}
if (con == 1)
cout << "\n\nEl programa converge!! LA RAIZ ES= "<<xr;
else
cout << "\n\nEl programa NO CONVERGE!!";

//PROGRAMA NUMERO 10: METODOO ELIMINACION DE GAUSS


//DANIEL MEMIJE GARDUO
#include<iostream>
#include<math.h>
#include<conio.h>
using namespace std;
//funcion que resulve una matriz por el metodo de eliminacion de gauss
void egauss(int, float [20][21], float [20]);
void escribevect(int, float[20], char[5]);
void main()
{
{

GAUSS \n";

int n, i, j;
float a[20][21], x[20];
cout << "\n
PROGRAMA NUMERO 10: METODOO ELIMINACION DE
//aqui se introduce el numero de ecuaciones a resolver
cout << "Cuantas ecuaciones vas a resolver= "; cin >> n;
cout << "\n\n";
//llenado de la matriz
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n + 1; j++)
{
if (j != n + 1)
{
cout << "a[" << i << "," << j << "]= "; cin >> a[i][j];
}
else
{
cout << "\n y[" << i <<"]= "; cin >> a[i][j];
cout << "\n";
}
}
}
//llamado de la funcion para implementar el metodo
egauss(n, a, x);
escribevect(n, x, "x");

_getch();

}
//*******************aqui se definen las funciones**********************
void egauss(int n, float a[20][21], float x[20])

{
int i, j, k;
float aux;
//matriz triangular superior
for (i = 1; i <= n; i++)
{
aux = a[i][i];
for (j = i; j <= n + 1; j++)
a[i][j] = a[i][j] / aux;
for (j = i + 1; j <= n; j++)
{
aux = a[j][i];
for (k = 1; k <= n+1; k++)
a[j][k] = a[j][k] - a[i][k] * aux;
}
}
//eliminacion hacia atras
x[n] = a[n][n + 1];
for (i = n - 1; i >= 1; i--)
{
x[i] = a[i] [n + 1];
for (j = i + 1; j <= n;j++)
x[i] = x[i]-a[i][j]*x[j];
}
}
void escribevect(int n, float x[50], char nom[5])
{
int i;
for (i = 1; i <= n; i++)
cout << "\n" << nom << "[" << i << "]= " << x[i];
}

//PROGRAMA NUMERO 11: METODOO ELIMINACION DE GAUSS JORDAN


//DANIEL MEMIJE GARDUO
#include<iostream>
#include<math.h>
#include<conio.h>
using namespace std;
//funcion que resulve una matriz por el metodo de eliminacion de gauss
void egauss(int, float[20][21], float[20]);
void escribevect(int, float[20], char[5]);
void main()
{
{
int n, i, j;
float a[20][21], x[20];;
cout << "\n

PROGRAMA NUMERO 11: METODOO ELIMINACION DE GAUSS

JORDAN \n";
//aqui se introduce el numero de ecuaciones a resolver
cout << "\n\nCuantas ecuaciones vas a resolver= "; cin >> n;
cout << "\n\n";
//llenado de la matriz
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n + 1; j++)
{
if (j != n + 1)
{
cout << "a[" << i << "," << j << "]= "; cin >> a[i][j];
}
else
{
cout << "\n y[" << i << "]= "; cin >> a[i][j];
cout << "\n";
}
}
}
//llamado de la funcion para implementar el metodo
egauss(n, a, x);
escribevect(n, x, "x");
_getch();
}
}
//*******************aqui se definen las funciones**********************
void egauss(int n, float a[20][21], float x[20])
{
int i, j, k;

float aux;

//matriz triangular superior


for (i = 1; i <= n; i++)
{
aux = a[i][i];
for (j = i; j <= n + 1; j++)
a[i][j] = a[i][j] / aux;
for (j = i + 1; j <= n; j++)
{
aux = a[j][i];
for (k = 1; k <= n + 1; k++)
a[j][k] = a[j][k] - a[i][k] * aux;
}
}
//MATRIZ DE GAUSS JORDAN
for (i = n; i >= 1; i--)
{
aux = a[i][i];
for (j = n+1; j >= i; j--)
a[i][j] = a[i][j] / aux;
for (j = i - 1; j >= 1; j--)
{
aux = a[j][i];
for (k = 1; k <= n + 1; k++)
a[j][k] = a[j][k] - a[i][k] * aux;
}
}
for (i = 1; i <= n; i++)
x[i] = a[i][n+1];

void escribevect(int n, float x[50], char nom[5])


{
int i;
for (i = 1; i <= n; i++)
cout << "\n" << nom << "[" << i << "]= " << x[i];
}

//PROGRAMA NUMERO 13: METODOO MINIMOS CUADRADOS

//DANIEL MEMIJE GARDUO


#include<iostream>
#include<math.h>
#include<conio.h>
using namespace std;
//funcion que resulve una matriz por el metodo de eliminacion de gauss
void minicua(int,int, float[20], float[20]);
void leevect(int, float[20], char[5]);
void escribevect(int, float[20], char[5]);
void egauss(int, float[20][21], float[20]);
void main()
{
int n, grado;
float x[20], y[20];
cout << "\n

PROGRAMA NUMERO 13: METODOO MINIMOS CUADRADOS \n";

//aqui se introduce el numero de ecuaciones a resolver


cout << "\n\nCuantos puntos quieres aproximar por este metodo?= "; cin >> n;
cout << "Cual sera el grado del polinomio?= "; cin >> grado;
if (grado > n - 1)
{
cout << "Error!! El numero de datos no es suficiente!!";
_getch();
;
}
cout << "\n\n";
//Aqui se introducen los puntos
leevect(n, x, "x");
leevect(n, y, "y");
//llamado a la funcion
minicua(n,grado, x, y);
//impresion de resultados
escribevect(grado+1, x, "a");
_getch();
}
//*******************aqui se definen las funciones**********************
void minicua(int n, int grado, float x[20], float y[20])
{
int i, j, k;
float a[20][21], m[40], l[40],sum;
m[1] = n;
l[1] = 0;
for (i = 1; i <= n; i++)
l[1] = l[1] + y[i];
for (i = 2; i <= 2*(grado+1); i++)

{
m[i] = 0;
l[i] = 0;
for (j = 1; j <= n; j++)
{
m[i] = m[i] + pow(x[j], i - 1);
if (i <= grado + 1)
l[i ] = l[i] + y[j] * pow(x[j], i - 1);
}

}
j = 0;
for (i = 1; i <= grado+1; i++)
{
for (k = 1; k <= grado+1; k++)
{
a[i][k] = m[k + j];
cout << "\na[" << i << "," << k << "]= " << a[i][k];
if (k == grado+1)
a[i][k + 1] = l[i];
cout << "\na[" << i << "," << k +1<< "]= " << a[i][k+1];
}
j++;
}
egauss(grado+1, a, x);

void egauss(int n, float a[20][21], float x[20])


{
int i, j, k;
float aux;
//matriz triangular superior
for (i = 1; i <= n; i++)
{
aux = a[i][i];
for (j = i; j <= n + 1; j++)
a[i][j] = a[i][j] / aux;
for (j = i + 1; j <= n; j++)
{
aux = a[j][i];
for (k = 1; k <= n + 1; k++)
a[j][k] = a[j][k] - a[i][k] * aux;
}
}
//eliminacion hacia atras
x[n] = a[n][n + 1];
for (i = n - 1; i >= 1; i--)
{
x[i] = a[i][n + 1];
for (j = i + 1; j <= n; j++)
x[i] = x[i] - a[i][j] * x[j];
}
}
void escribevect(int n, float x[50], char nom[5])
{
int i;

for (i = 1; i <= n; i++)


cout << "\n" << nom << "[" << i-1 << "]= " << x[i];

void leevect(int n, float x[50], char nom[5])


{
int i;
for (i = 1; i <= n; i++)
{
cout << nom << "Introduce el valor de"<<nom<<"[" << i << "]= "; cin >>
x[i];
}
}

//PROGRAMA NUMERO 14: METODOO DE EULER PARA ECUACIONES DIFERENCIALES


//DANIEL MEMIJE GARDUO

#include<iostream>
#include<math.h>
#include<conio.h>
#define df(x)(-2*pow(x,3)+12*pow(x,2)-20*x+8.5)
using namespace std;
//funcion que resulve una matriz por el metodo de eliminacion de gauss
void euler(int, float, float, float);
void main()
{
int nit;
float xi,yi, xf, h, x0, y0, x, y;
cout << "\n
DIFERENCIALES \n";

PROGRAMA NUMERO 14: METODOO DE EULER PARA ECUACIONES

//aqui se introduce los valores inicial y final asi como el tamao de paso
cout << "\nDame X inicial= "; cin >> xi;
cout << "\nDame Y inicial= "; cin >> yi;
cout << "\nDame el tamoo del paso de integracion h= "; cin >> h;
cout << "\nDame el punto donde deseas calcular Y final= "; cin >> xf;
x = xi;
y = yi;
nit = (xf - xi) / h;
//llamado de la funcion
euler(nit, x, y, h);
}

_getch();

//*******************aqui se definen las funciones**********************


void euler(int n , float x, float y, float h)
{
int i;
cout << "\n x
y ";
for (i = 1; i <= n; i++)
{
cout << "\n" << x << "
y = y + df(x)*h;
x = x + h;
}
}

" << y;

También podría gustarte