Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void sum(int a, int b) {
- b = 17;
- cout << a << " " << b << endl;
- }
- int solve_eq(double coeff[], double sol[]) {
- // returns number of roots
- // koeff = {a, b, c}
- // a * x * x + b * x + c = 0, sol = {x1, x2}
- const double a = coeff[0],
- b = coeff[1],
- c = coeff[2];
- double eps = DBL_EPSILON; // 1.0e-10;//_DOUBLE_EPS;
- if (abs(a) <= eps) {
- sol[0] = -c / b;
- return 1;
- }
- // discriminant
- double d = b * b - 4 * a * c;
- if (d < 0) {
- return 0;
- }
- d = sqrt(d);
- sol[0] = (-b - d) / (2 * a);
- sol[1] = (-b + d) / (2 * a);
- return 2;
- }
- double check_solve_eq(double coeff[], double x) {
- const double a = coeff[0],
- b = coeff[1],
- c = coeff[2];
- return a * x * x + b * x + c;
- }
- void analitic_task() {
- double abc[]{-1, -2, -5};
- double xs[2];
- int num = solve_eq(abc, xs);
- for (int k = 0; k < num; k++)
- cout << "root: " << xs[k] << " "
- << "precision: "
- << check_solve_eq(abc, xs[k]) << endl;
- cout << endl;
- }
- double check_function(double params[], double x) {
- return params[0] * tan(params[1] * x) - params[2];
- }
- void numeric_task() {
- // function(x)
- double p[]{1.1, 0.5, 10};
- double val;
- double sol = -100;
- double min = abs(check_function(p, sol));
- for (double x = -100; x <= 100; x += 0.00001) {
- val = check_function(p, x);
- if (abs(val) < min) {
- min = abs(val);
- sol = x;
- }
- //if(abs(val) < 0.02)
- // cout << x << " " << val << endl;
- }
- cout << sol << " " << min << endl;
- }
- void test_colors() {
- cout << "\033[33mTest" << endl;
- cout << "Hoba";
- for (int id = 0; id <= 108; id++) {
- cout << "\033[" << id << "m "
- << id << "\033[0m";
- if ((id + 1) % 20 == 0)
- cout << endl;
- }
- cout << endl;
- cout << "\033[41;32m GOOD DAY \033[0m" << endl;
- }
- int main() {
- //analitic_task();
- //numeric_task();
- /*
- int a = 4;
- int b = -4;
- sum(a, b);
- cout << a << " " << b << endl;
- */
- test_colors();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment