Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstdio>
- #define M_PI 3.14159265358979323846
- using namespace std;
- double f(double x){
- return x*x-4;
- }
- double g(double x){
- return sin(2*x);
- }
- //double f(double x){
- // return -x*x/50.0;
- //}
- //double g(double x){
- // return 1+x*x/100.0-x/200.0;
- //}
- double pole(double a, double b, double h){
- double S = 0;
- double x0 = a;
- double x1 = x0+h;
- while(x0<=b){
- S+=(g(x0)-f(x0)+g(x1)-f(x1))*h/20.0;
- x0 = x1;
- x1+=h;
- }
- return S;
- }
- int retC(int &a, int &b){
- int i,j;
- for(i=0; g(i)-f(i)<26; i++);
- i+=100;
- for(j=0; g(j)-f(j)<100; j++);
- j+=26;
- if(i<j){
- a= 26;
- b= 100;
- return i;
- }
- else{
- a=100;
- b=26;
- return j;
- }
- }
- void wypisz(){
- int a,b;
- int c = retC(a,b);
- cout << "A = (" << c << ", " << g(c-b) << ") "<<endl;
- cout << "B = (" << c << ", " << g(c-b)-a << ") "<<endl;
- cout << "C = (" << c-b << ", " << g(c-b)-a << ") "<<endl;
- cout << "D = (" << c-b << ", " << g(c-b) << ") "<<endl;
- cout << "wartosci funkcji: " <<endl;
- cout <<f(58) << " " <<g(58) <<endl;
- }
- double bisekcjaF(double a, double b, double d){
- double sr;
- while(fabs(a-b)>d){
- sr= (a+b)/2;
- if(f(sr)*f(b)>0){
- b=sr;
- }
- else{
- a=sr;
- }
- }
- return sr;
- }
- double bisekcjaG(double a, double b, double d){
- double sr;
- while(fabs(a-b)>d){
- sr= (a+b)/2;
- if(g(sr)*g(b)>0){
- b=sr;
- }
- else{
- a=sr;
- }
- }
- return sr;
- }
- int main()
- {
- //zad.1.
- // cout << pole(0,10,0.01);
- // wypisz();
- //zad.2. bisekcja
- // cout << bisekcjaF(1,5,0.01);
- cout << bisekcjaG(5,10,0.0000001) <<endl;
- cout << 2* M_PI <<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement