Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include"stdafx.h"
- #include <iostream>
- #include <cmath>
- using namespace std;
- double F(double x) {
- return (pow(x, 4) - 13 * pow(x, 2) + 36 - (1 / x));
- }
- double BISECT(double Left, double Right, double Eps, int &N)
- {
- double E = fabs(Eps)*2.0;
- double FLeft = F(Left);
- double FRight = F(Right);
- double X = (Left + Right) / 2.0;
- double Y;
- if (FLeft*FRight>0.0) { puts("Interval\n"); exit(1); }
- if (Eps <= 0.0) { puts("Tochnost\n"); exit(1); }
- N = 0;
- if (FLeft == 0.0) return Left;
- if (FRight == 0.0) return Right;
- while ((Right - Left) >= E)
- {
- X = 0.5*(Right + Left); /* âû÷èñëåíèå ñåðåäèíû îòðåçêà */
- Y = F(X);
- if (Y == 0.0) return (X);
- if (Y*FLeft < 0.0)
- Right = X;
- else
- {
- Left = X; FLeft = Y;
- }
- N++;
- };
- return(X);
- }
- double Round(double X, double Delta)
- {
- if (Delta <= 1E-9) {
- puts("tochnost");exit(1);}
- if (X>0.0) return (Delta*(long((X / Delta) + 0.5)));
- else return (Delta*(long((X / Delta) - 0.5)));
- }
- int main() {
- int N=0;
- cout <<BISECT(0.0, 0.03, 0.0001, N)<<endl;
- cout << N;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement