Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <math.h>
- using namespace std;
- double f (double x)
- {
- return (x-5)*pow(M_E, x) + 5;
- }
- int main(int argc, char *argv[])
- {
- double a, b, epsilon, x0, f0;
- cout << "Podaj dolna granice przedzialu: ";
- cin >> a;
- cout << "Podaj gorna granice przedzialu: ";
- cin >> b;
- cout << "Podaj wymagana dokladnosc: ";
- cin >> epsilon;
- if (f(a)*f(b)>=0) {
- cout << "W zadanym przedziale funkcja f(x) nie ma miejsca zerowego.";
- exit(1);
- }
- else {
- do {
- x0 = (a*f(b)-b*f(a))/(f(b)-f(a));
- f0 = f(x0);
- if (f0 = 0) {
- cout << "Miejsce zerowe funkcji f(x) w podanym przedziale to: " << x0;
- } else {
- if (f(a)*f(x0) < 0) {
- x0 = a;
- } else {
- x0 = b;
- }
- }
- } while (fabs(b-a) >= epsilon);
- cout << "Miejscem zerowym jest: " << a;
- system("PAUSE");
- return EXIT_SUCCESS;
- }}
Add Comment
Please, Sign In to add comment