AlcoTrack.cpp

text/x-c++src AlcoTrack.cpp — 1 KB

File contents

#include<iostream>
#include<fstream>
#include<cmath>
#include<vector>
#include<cassert>
using namespace std;

// A=L*K^2
double Modell(double L, double K) {
  return L*K*K;
}

// L=...
double Optimierer(const vector<double>& K, 
                  const vector<double>& A) {
  int n=K.size();
  double L=0,d=0;
  for (int i=0;i<n;i++) {
    L+=pow(K[i],2)*A[i];
    d+=pow(K[i],4);
  }
  L/=d;
  return L;
}

int main(int c, char* v[]) {
  assert(c==2);
  fstream data;
  data.open(v[1],fstream::in);
  int n; data >> n; 
  vector<double> A(n),K(n);
  for (int i=0;i<n;i++) data >> K[i] >> A[i];
  data.close();
  double L=Optimierer(K,A);
  cout << "aktuelle Labilitaet "; cout << L << endl;
  double Kn, An;
  cout << "neuer Kompromiss? "; cin >> Kn;
  An=Modell(L,Kn);
  cout << "geschaetzte Abweichung " << An << endl;
  cout << "wirkliche Abweichung? "; cin >> An;
  data.open(v[1],fstream::out);
  data << n+1 << endl;
  for (int i=0;i<n;i++) 
    data << K[i] << " " << A[i] << endl;
  data << Kn << " " << An << endl;
  data.close();
  return 42;
}