Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <fstream>
- #include <iomanip>
- using namespace std;
- double exp_(double a)
- {
- double b = exp(-a);
- return (1.f - b) / a;
- }
- double bw(double przyblizona, double rzeczywista)
- {
- return fabs((przyblizona - rzeczywista) / rzeczywista);
- }
- double szereg(double x)
- {
- double suma = 1;
- double wyraz = 1;
- for (int i = 1; i <= 18; i++)
- {
- wyraz *= -x / (i + 1); // na przemian dodawanie i odejmowanie
- suma += wyraz;
- }
- return suma;
- }
- const double b_repr = pow(10, -16); // blad reprezentacji
- int main() {
- double fx, log10x, x, b_wz, blad, f_wyliczona;
- ifstream infile("dane.txt");
- ofstream output;
- output.open("wyniki.txt");
- while (infile >> log10x >> x >> fx)
- {
- f_wyliczona = exp_(x);
- b_wz = bw(f_wyliczona, fx);
- if (b_wz > b_repr)
- {
- f_wyliczona = szereg(x);
- blad = bw(f_wyliczona, fx);
- }
- if (blad < b_wz)
- {
- b_wz = blad;
- }
- output << scientific << log10x << "\t" << log10(b_wz) << "\t" <<
- f_wyliczona << "\t" << fx << endl;
- }
- infile.close();
- output.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment