Advertisement
Guest User

Untitled

a guest
Nov 8th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. #pragma once
  2. struct Registro
  3. {
  4. Registro(float x, float y) {
  5. this->x = x;
  6. this->y = y;
  7. }
  8. void calcular(float promX,float promY) {
  9. dx = x - promX;
  10. dy = y - promY;
  11. dx2 = dx*dx;
  12. dy2 = dy*dy;
  13. dxdy = dx*dy;
  14. }
  15. void mostrar() {
  16. cout << x << " " << y << " " << dx << " "<<dy<<" " <<dxdy<<" "
  17. <<" "<<dx2 << " " << dy2 <<endl;
  18. }
  19. ~Registro(){}
  20. float x,y,dx,dy,dx2,dy2,dxdy;
  21. };
  22. class Dataframe {
  23. private:
  24. vector<Registro> coleccion;
  25. float promX, promY, sumDxy,
  26. covXY, sumDxx, sumDyy, sdX, sdY;
  27. public:
  28. Dataframe(){
  29. }
  30. void limpiar() { coleccion.clear(); }
  31. void agregar(float x, float y) {
  32. coleccion.push_back(Registro(x, y));
  33. }
  34. float calcularR() {
  35. return covXY / (sdX*sdY);
  36. }
  37. float predecirX(float ny) {
  38. return promY + ((ny - promY)*covXY / (sdY*sdY));
  39. }
  40. float predecirY(float nx) {
  41. return promX + ((nx - promX)*covXY / (sdX*sdX));
  42. }
  43. void calcularTabla(){
  44. promX = promY=0;
  45. //Calcular Promedio
  46. for (int i = 0; i < coleccion.size(); ++i) {
  47. promX += coleccion[i].x;
  48. promY += coleccion[i].y;
  49. }
  50. promX /= coleccion.size();
  51. promY /= coleccion.size();
  52. /////////Calcular Tabla
  53. for (int i = 0; i < coleccion.size(); ++i) {
  54. coleccion[i].calcular(promX,promY);
  55. coleccion[i].mostrar();
  56. }
  57. ////////Calcular Resultados
  58. sumDxy =sumDxx =sumDyy = 0;
  59. for (int i = 0; i < coleccion.size(); ++i) {
  60. sumDxy += coleccion[i].dxdy;
  61. sumDxx += coleccion[i].dx2;
  62. sumDyy += coleccion[i].dy2;
  63. }
  64. int l = coleccion.size();
  65. covXY = sumDxy / (l - 1);//covarianza muestral
  66. sdX = sqrt(sumDxx / (l - 1));
  67. sdY = sqrt(sumDyy / (l - 1));
  68.  
  69. }
  70. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement