#include <iostream> #include <math.h> #include <iomanip> #include <limits> using namespace std; double f_tan(double i); double f_sin_2(double i); double f_sin(double i); double add_phase(double x, double phase = M_PI_2); int main() { int numb_of_loop = 5; double shift = 0; double shift_step = 0.01; for (int j=0; j < 3*numb_of_loop; j++ ) { for (int i=0; i < numb_of_loop; i++ ) { cout << "tan(x) = " << f_tan(i + shift) << std::setw(17) << "sin(x)^2 = " << f_sin_2(i + shift) << std::setw(17) << "sin(x)/x = " << f_sin(i+shift) << endl; } cout << "----------------------" << endl; shift = shift + shift_step; } return 0; } double f_tan(double i) { double x = add_phase(i*M_PI,M_PI_4); if (cos(x) == 0) { return std::numeric_limits<double>::infinity(); } return tan(x); } double f_sin_2(double i) { double x = add_phase(i*M_PI); double y = sin(x); return y*y; } double f_sin(double i) { double x = add_phase(i*2*M_PI,M_PI_4); if (x < 0.00001) { return std::numeric_limits<double>::infinity(); } return sin(x)/x; } double add_phase(double x, double phase) { return x + phase; }
Standard input is empty
tan(x) = 1 sin(x)^2 = 1 sin(x)/x = 0.900316 tan(x) = 1 sin(x)^2 = 1 sin(x)/x = 0.100035 tan(x) = 1 sin(x)^2 = 1 sin(x)/x = 0.0529598 tan(x) = 1 sin(x)^2 = 1 sin(x)/x = 0.0360127 tan(x) = 1 sin(x)^2 = 1 sin(x)/x = 0.0272823 ---------------------- tan(x) = 1.06489 sin(x)^2 = 0.999013 sin(x)/x = 0.884325 tan(x) = 1.06489 sin(x)^2 = 0.999013 sin(x)/x = 0.105184 tan(x) = 1.06489 sin(x)^2 = 0.999013 sin(x)/x = 0.0559175 tan(x) = 1.06489 sin(x)^2 = 0.999013 sin(x)/x = 0.038081 tan(x) = 1.06489 sin(x)^2 = 0.999013 sin(x)/x = 0.0288716 ---------------------- tan(x) = 1.13428 sin(x)^2 = 0.996057 sin(x)/x = 0.86729 tan(x) = 1.13428 sin(x)^2 = 0.996057 sin(x)/x = 0.109832 tan(x) = 1.13428 sin(x)^2 = 0.996057 sin(x)/x = 0.058628 tan(x) = 1.13428 sin(x)^2 = 0.996057 sin(x)/x = 0.0399864 tan(x) = 1.13428 sin(x)^2 = 0.996057 sin(x)/x = 0.0303395 ---------------------- tan(x) = 1.20879 sin(x)^2 = 0.991144 sin(x)/x = 0.849251 tan(x) = 1.20879 sin(x)^2 = 0.991144 sin(x)/x = 0.113969 tan(x) = 1.20879 sin(x)^2 = 0.991144 sin(x)/x = 0.061083 tan(x) = 1.20879 sin(x)^2 = 0.991144 sin(x)/x = 0.0417223 tan(x) = 1.20879 sin(x)^2 = 0.991144 sin(x)/x = 0.0316809 ---------------------- tan(x) = 1.28919 sin(x)^2 = 0.984292 sin(x)/x = 0.830251 tan(x) = 1.28919 sin(x)^2 = 0.984292 sin(x)/x = 0.117589 tan(x) = 1.28919 sin(x)^2 = 0.984292 sin(x)/x = 0.0632754 tan(x) = 1.28919 sin(x)^2 = 0.984292 sin(x)/x = 0.0432832 tan(x) = 1.28919 sin(x)^2 = 0.984292 sin(x)/x = 0.0328911 ---------------------- tan(x) = 1.37638 sin(x)^2 = 0.975528 sin(x)/x = 0.810332 tan(x) = 1.37638 sin(x)^2 = 0.975528 sin(x)/x = 0.120688 tan(x) = 1.37638 sin(x)^2 = 0.975528 sin(x)/x = 0.0651991 tan(x) = 1.37638 sin(x)^2 = 0.975528 sin(x)/x = 0.044664 tan(x) = 1.37638 sin(x)^2 = 0.975528 sin(x)/x = 0.033966 ---------------------- tan(x) = 1.47146 sin(x)^2 = 0.964888 sin(x)/x = 0.789542 tan(x) = 1.47146 sin(x)^2 = 0.964888 sin(x)/x = 0.123262 tan(x) = 1.47146 sin(x)^2 = 0.964888 sin(x)/x = 0.0668491 tan(x) = 1.47146 sin(x)^2 = 0.964888 sin(x)/x = 0.0458603 tan(x) = 1.47146 sin(x)^2 = 0.964888 sin(x)/x = 0.0349021 ---------------------- tan(x) = 1.57575 sin(x)^2 = 0.952414 sin(x)/x = 0.767927 tan(x) = 1.57575 sin(x)^2 = 0.952414 sin(x)/x = 0.12531 tan(x) = 1.57575 sin(x)^2 = 0.952414 sin(x)/x = 0.0682213 tan(x) = 1.57575 sin(x)^2 = 0.952414 sin(x)/x = 0.0468688 tan(x) = 1.57575 sin(x)^2 = 0.952414 sin(x)/x = 0.0356963 ---------------------- tan(x) = 1.69091 sin(x)^2 = 0.938153 sin(x)/x = 0.745539 tan(x) = 1.69091 sin(x)^2 = 0.938153 sin(x)/x = 0.126834 tan(x) = 1.69091 sin(x)^2 = 0.938153 sin(x)/x = 0.0693131 tan(x) = 1.69091 sin(x)^2 = 0.938153 sin(x)/x = 0.0476866 tan(x) = 1.69091 sin(x)^2 = 0.938153 sin(x)/x = 0.0363461 ---------------------- tan(x) = 1.81899 sin(x)^2 = 0.922164 sin(x)/x = 0.722428 tan(x) = 1.81899 sin(x)^2 = 0.922164 sin(x)/x = 0.127837 tan(x) = 1.81899 sin(x)^2 = 0.922164 sin(x)/x = 0.0701228 tan(x) = 1.81899 sin(x)^2 = 0.922164 sin(x)/x = 0.0483117 tan(x) = 1.81899 sin(x)^2 = 0.922164 sin(x)/x = 0.0368498 ---------------------- tan(x) = 1.96261 sin(x)^2 = 0.904508 sin(x)/x = 0.698647 tan(x) = 1.96261 sin(x)^2 = 0.904508 sin(x)/x = 0.128323 tan(x) = 1.96261 sin(x)^2 = 0.904508 sin(x)/x = 0.0706497 tan(x) = 1.96261 sin(x)^2 = 0.904508 sin(x)/x = 0.0487428 tan(x) = 1.96261 sin(x)^2 = 0.904508 sin(x)/x = 0.037206 ---------------------- tan(x) = 2.12511 sin(x)^2 = 0.885257 sin(x)/x = 0.674249 tan(x) = 2.12511 sin(x)^2 = 0.885257 sin(x)/x = 0.128298 tan(x) = 2.12511 sin(x)^2 = 0.885257 sin(x)/x = 0.0708942 tan(x) = 2.12511 sin(x)^2 = 0.885257 sin(x)/x = 0.0489795 tan(x) = 2.12511 sin(x)^2 = 0.885257 sin(x)/x = 0.0374141 ---------------------- tan(x) = 2.31086 sin(x)^2 = 0.864484 sin(x)/x = 0.649291 tan(x) = 2.31086 sin(x)^2 = 0.864484 sin(x)/x = 0.127772 tan(x) = 2.31086 sin(x)^2 = 0.864484 sin(x)/x = 0.0708581 tan(x) = 2.31086 sin(x)^2 = 0.864484 sin(x)/x = 0.049022 tan(x) = 2.31086 sin(x)^2 = 0.864484 sin(x)/x = 0.0374738 ---------------------- tan(x) = 2.52571 sin(x)^2 = 0.842274 sin(x)/x = 0.623829 tan(x) = 2.52571 sin(x)^2 = 0.842274 sin(x)/x = 0.126754 tan(x) = 2.52571 sin(x)^2 = 0.842274 sin(x)/x = 0.0705439 tan(x) = 2.52571 sin(x)^2 = 0.842274 sin(x)/x = 0.0488714 tan(x) = 2.52571 sin(x)^2 = 0.842274 sin(x)/x = 0.0373858 ---------------------- tan(x) = 2.77761 sin(x)^2 = 0.818712 sin(x)/x = 0.597919 tan(x) = 2.77761 sin(x)^2 = 0.818712 sin(x)/x = 0.125256 tan(x) = 2.77761 sin(x)^2 = 0.818712 sin(x)/x = 0.0699552 tan(x) = 2.77761 sin(x)^2 = 0.818712 sin(x)/x = 0.0485294 tan(x) = 2.77761 sin(x)^2 = 0.818712 sin(x)/x = 0.0371509 ----------------------