Results 1 to 2 of 2
Thread: , !
Hybrid View
-
4th February 2012 00:25 #1
, !
,
:
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]?
, , ...
,
-
4th February 2012 01:26 #2Registered User
Join Date: Oct:2003
Location:
Posts: 4,317




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in