Skip to content

Instantly share code, notes, and snippets.

@niklasbuschmann
Last active June 5, 2020 17:22
Show Gist options
  • Save niklasbuschmann/98f07e338146d643809967bb02676608 to your computer and use it in GitHub Desktop.
Save niklasbuschmann/98f07e338146d643809967bb02676608 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include <sstream>
#include <vector>
using namespace std;
string map[] = {".", ",", "~", "=", "+", ":", "?", "$", "7", "8", "D", "I", "M", "N", "O", "Z"};
void print(string filename) {
int x, y, i, j;
string str;
ifstream file(filename);
file >> x;
file >> y;
cout << endl << endl << filename << endl;
while (file >> i && file >> j) {
for (int n = 0; n < j; n++)
str.append(map[i]);
}
for (int n = 0; n < str.length(); n++) {
if (n % x == 0)
cout << endl;
cout << str[n];
}
}
int main() {
for (int i = 1; i <= 4; i++)
print("a15-bild" + to_string(i) + ".dat");
}
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include <sstream>
#include <vector>
using namespace std;
vector<double> x, y;
double L(int i, double input) {
double product = 1;
for (int k = 0; k < x.size(); k++)
product *= (i == k) ? 1 : (input - x[k]) / (x[i] - x[k]);
return product;
}
double f(double input) {
double sum = 0;
for (int i = 0; i < y.size(); i++)
sum += y[i] * L(i, input);
return sum;
}
void getfile(string filename) {
double i, j;
ifstream file(filename);
while (file >> i >> j) {
x.push_back(i);
y.push_back(j);
}
}
int main() {
double input;
ofstream output("a16-interpol-res.dat");
getfile("a16-interpol.dat");
while (true) {
cout << "x: ";
cin >> input;
if (input == 0)
break;
cout << "y: " << f(input) << endl;
output << input << " " << f(input) << endl ;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment