You are on page 1of 2

#include <iostream> #include <conio.h> #include <stdlib.

h> #define max 50 using namespace std; //Funcion para Leer los datos void leer(float *x ,float *y,int n) {int i; for(i=0;i<n;i++,x++) {cout<<"Ingrese el valor de X n "<<(i+1)<<": "; cin>>*x; system("cls"); } for(i=0;i<n;i++,y++) {cout<<"Ingrese el valor de Y n "<<(i+1)<<": "; cin>>*y; system("cls"); } } //Funcion para calcular la Pendiente ajustada por minimos cuadrados void minimos_cuadrados(float *x,float *y,int n) {float k=0,t=0,w=0,k2=0,m; int i; //Efectuando las respectivas sumas y productos requeridos en la ecuacion for(i=0;i<n;i++,x++,y++) {k+=*x; t+=*y; w+= (*x)*(*y); k2+=(*x)*(*x); } //Resolviendo la ecuacion de la Pendiente ajustada a minimos cuadrados m=(n*w-k*t)/(n*k2-k*k); cout<<"La pendiente ajustada por minimos cuadrados es m= "<<m<<endl; } //Funcion para calcular el punto de corte void punto(float *x,float *y,int n) {float k=0,t=0,w=0,k2=0,b; int i; //Efectuando las respectivas sumas y productos requeridos en la ecuacion for(i=0;i<n;i++,x++,y++) {k+=*x; t+=*y; w+= (*x)*(*y); k2+=(*x)*(*x); } //Resolviendo la ecuacion para hallar el punto de corte por minimos cuadrados b=(t*k2-k*w)/(n*k2-k*k); cout<<"\nEl punto de corte por minimos cuadrados es b= "<<b<<endl; } //Funcin Principal int main () {int n,i; char c; float x[max],y[max]; cout<<"\t\t**PROGRAMA PARA AJUSTAR RECTA POR MINIMOS CUADRADOS**"; cout<<"\t\t\t\t\tELABORADO POR: JUAN PASTOR RAMOS BOLIVAR"<<endl; cout<<"\t\t\t\tUDO-INGENIERIA EN COMPUTACION"<<endl; cout<<"\t\t\t\tTODOS LOS DERECHOS RESERVADOS" ; for(i=0;i<19;i++) cout<<endl;

cout<<"\t\t\t\tPresione enter para continuar..."; getch(); system("cls"); do{ do{ cout<<"Ingrese la cantidad de datos a procesar: "; cin>>n; system("cls"); if(n<2 n>max) cout<<"Ingrese un valor entre [2,50]"<<endl; }while(n<2 n>max);

leer(x,y,n); minimos_cuadrados(x,y,n); punto(x,y,n); do{ cout<<"\nDesea realizar otro ajuste por minimos cuadrados? pulse s o n..."<<end l; c=getch(); system("cls"); }while(c!='s' && c!='S' && c!='n' && c!='N'); }while(c=='s' c=='S'); if (c=='n' c=='N') return 0; }

You might also like