Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <math.h>
- #include <cmath>
- using namespace std;
- void bisekcja(float a, float b, float eps);
- float funkcja(float x);
- float funkcja2(float x);
- float funkcja3(float x);
- int main()
- {
- int liczba = 0;
- do {
- cout << "MENU" << endl;
- cout << "1. Pierwiastek funkcji f1(x) = sin(x)cos(x)+5x+1" << endl;
- cout << "2. Pierwiastek funkcji f2(x) = (π-x*x+sin(x))/sqrt(25-x)" << endl;
- cout << "3. Pierwiastek funkcji f3(x) = exp(-1.5x)-0.3x*x" << endl;
- cout << "4. Koniec" << endl;
- cin >> liczba;
- switch (liczba)
- {
- case 1:
- break;
- }
- }
- while (liczba != 4);
- /**
- float a, b, eps, c, pierw;
- cout << "Podaj a: " << endl;
- cin >> a;
- cout << "Podaj b: " << endl;
- cin >> b;
- cout << "Podaj eps: " << endl;
- cin >> eps;
- bisekcja(a, b, eps);
- */
- _getch();
- }
- float funkcja(float x)
- {
- float f;
- f = sin(x)*cos(x)+5*x+1;
- return f;
- }
- float funkcja2(float x)
- {
- float f;
- f = (3.14 - x*x + sin(x)) / sqrt(25 - x);
- return f;
- }
- float funkcja3(float x)
- {
- float f;
- f = exp(-1.5*x) - 0.3*x*x;
- return f;
- }
- void bisekcja(float a, float b, float eps)
- {
- float pierw, c, i;
- i = 0;
- if (funkcja(a) == 0)
- {
- pierw = a;
- cout << "Pierwiastek: " << a << endl;
- }
- else
- {
- if (funkcja(b) == 0)
- cout << "Pierwiastek: " << b << endl;
- pierw = b;
- }
- do
- {
- c = (a + b) / 2;
- if (funkcja(c) == 0)
- {
- pierw = c;
- }
- if (funkcja(a)*funkcja(c)<0)
- {
- b = c;
- }
- else
- a = c;
- i++;
- } while (abs(a - b) >= eps);
- pierw = c;
- cout << "Pierwiastek" << c << endl;
- cout << "Liczba iteracji" << i << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement