Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <cmath>
  4. #include <fstream>
  5. #include <vector>
  6. using namespace std;
  7.  
  8. double x;
  9. double y;
  10.  
  11. vector<double> xf;
  12. vector<double> yf;
  13. vector<double> yfORG;
  14.  
  15. double srednia(vector<double> v) {
  16. double suma = 0;
  17. for (int i=0; i<v.size(); i++) {
  18. suma += v[i];
  19. }
  20. return suma/v.size();
  21. }
  22.  
  23. int main() {
  24. int wezly;
  25. cout << "Podaj ilosc wezlow: ";
  26. cin >> wezly;
  27.  
  28. vector<double> x2f; // wektor wartosci x podniesionych do kwadratu
  29. vector<double> xy; // wektor pomnozonych wartosci x z wartosciami y.
  30.  
  31. for (int i = 0; i < wezly; i++) {
  32. cout << "Podaj wartosc x dla " << i + 1 << ". wezla: ";
  33. double xVal;
  34. cin >> xVal;
  35. xf.push_back(xVal);
  36. x2f.push_back(xVal * xVal);
  37. cout << "Podaj wartosc y dla " << i + 1 << ". wezla: ";
  38. double yVal;
  39. cin >> yVal;
  40. yfORG.push_back(yVal);
  41. yVal = log(yVal);
  42. yf.push_back(yVal);
  43. xy.push_back(xVal * yVal);
  44. }
  45.  
  46. double srXf = srednia(xf);
  47. double srYf = srednia(yf);
  48. double srX2f = srednia(x2f);
  49. double srXy = srednia(xy);
  50.  
  51. double A = (srXy - srXf * srYf) / (srX2f - srXf * srXf);
  52. double B = srYf - A * srXf;
  53.  
  54. cout << "A = " << A << ", " << "B = " << B;
  55.  
  56. fstream plik;
  57. plik.open("daneK.txt", ios::out);
  58. for (int i = 0; i < wezly; i++) {
  59. plik << xf[i] << " " << yfORG[i] << endl;
  60. }
  61. plik.close();
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement