Results 1 to 2 of 2

Thread: , !

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User vlex's Avatar
    Join Date: Jan:2008
    Location: Sofia
    Posts: 340

    , !

    ,

    :

    6. root, f(x)=0 (a,b) eps. , root : double (*f)(double). : double fsin(double) double fcos(double) - main, root .
    PHP Code:
    #include <iostream>
    double root(double a,double b,double eps,double (*f)(double)){
        
    double fa=f(a),fb=f(b),x,fx=1;//     f
        
    if(fa*fb>=0)return a-1;
        while(
    fabs(fx)>eps||fabs(b-a)>eps){
            
    x=(a+b)*0.5;fx=f(x);        //  
            
    if(fx*fa>0){a=x;fa=fx;}
            else 
    b=x;
        }
        return 
    x;
    }
    double fsin(double x){return sin(x)-0.001*x;}
    double fcos(double x){return cos(x)-x;}
    void main(){using namespace std;
        
    cout<<root(0.1,4,0.00001,fsin)<<endl;
        
    cout<<root(0,1.5,0.00001,fcos)<<endl;

    , . , . :

    , , 4 - ,, (*f), ( - fsin/fcos(); ). - , ()*() -, -1 ? while ?! fx ( 1), , f(x)=0 [a;b]?

    , , ...

    ,

  2. #2
    Registered User
    Join Date: Oct:2003
    Location:
    Posts: 4,317

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |