Results 1 to 17 of 17
Thread: ++
Hybrid View
-
5th April 2008 04:05 #1Registered User
Join Date: Apr:2008
Location: Bulgaria
Posts: 3
++
. .
:
. , , ( -1) ( - + ) :Code:#include <iostream> using namespace std; #include <math.h> double F(double x) { double res = pow(x, 3) - pow(x, 2) + 8 * pow(x, 2) -12; return res; } void print_roots(){ double low , high; // cout<<"low=";cin>>low; cout<<"high=";cin>>high; for(int i = 0; i < 1000 ; ++i){ double mid = (float)(low + high)/2; double val = F(mid); cout << mid << ":" << val << endl; if(val < 0.00001 && val > -0.00001){ cout << "Root is " << mid << endl; return; } else if (val < 0 ) low = mid; else high = mid; } } int main(int argc, char **argv){ print_roots(); system("pause"); return 0; }
double res = pow(x, 9) - pow(x, 7) + 2 * pow(x, 2) -1;
.
.
mid = 0.
. 0 0. 6 .
.
.
-
5th April 2008 13:16 #2
, - (.. , 1, -1, 2 -1, 9, 7, 2 0. " " - - .
, - 'x' F mid? , . , , mid for . .. "" . , cout << mid << ":" ..., . .
"640K ught to be enough for anybody" - Bill Gates, 1981
::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel
-
6th April 2008 11:34 #3
, ? ? :
pow(x, 3) - pow(x, 2) + 8 * pow(x, 2) -12 = 0 ?!
@anrieff , -:
double F(double x), : .
:
, . !
1) : double mid = (float)(low + high)/2; ( float?!), :
double mid = (high - low)/2;
, , , . , , , .
, . , :
pow(x,2)-1 = 0 [0,3] 10- 1 (
)
.. , - . . + , .
: ( ) -> .Last edited by Kaspirtov; 6th April 2008 at 11:53.
" , , , , ."
-
6th April 2008 17:46 #4
-
6th April 2008 18:11 #5
-
10th April 2008 04:02 #6Registered User
Join Date: Dec:2007
Location:
Posts: 655
-
10th April 2008 09:34 #7
-
10th April 2008 12:31 #8Registered User
Join Date: Dec:2007
Location:
Posts: 655
-
10th April 2008 12:48 #9
-
6th April 2008 19:08 #10
low/high , .
, ? , ,
Internet - it doesn't make you stupid, it just makes your stupidity more accessible to others
-
6th April 2008 19:26 #11
-
7th April 2008 05:27 #12Registered User
Join Date: Jul:2006
Location:
Posts: 480
" ", . K ...
.
, .
[A;B], -. F(c)=0, . [A;C], [C;B], .Code:C=(A+B)/2
E, : . [A;B], - E. X, - , - E, . . :
:Code:[ A, B E] REPEAT C=(A+B)/2 ; IF F(C)=0 THEN BREAK ; ELSE IF F(C)*F(A)>0 THEN A=C ; ELSE B=C ; UNTIL ABS(A-B)<=E ; PRINT "KORENYT E X=",C ;
IF A>B THEN [ ].
:
DO-WHILE - ABS(A-B)>E




Reply With Quote



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