Sgn value of a polynomial | returns value of poly [ 0 ] x ( n - 1 ) + poly [ 1 ] x ( n - 2 ) + . . + poly [ n - 1 ] ; Initialize result ; Evaluate value of polynomial using Horner 's method ; Returns sign value of polynomial ; Let us evaluate value of 2 x3 - 6 x2 + 2 x - 1 for x = 3
< ? php function horner ( $ poly , $ n , $ x ) { $ result = $ poly [ 0 ] ; for ( $ i = 1 ; $ i < $ n ; $ i ++ ) $ result = $ result * $ x + $ poly [ $ i ] ; return $ result ; } function findSign ( $ poly , $ n , $ x ) { $ result = horner ( $ poly , $ n , $ x ) ; if ( $ result > 0 ) return 1 ; else if ( $ result < 0 ) return -1 ; return 0 ; } $ poly = array ( 2 , -6 , 2 , -1 ) ; $ x = 3 ; $ n = count ( $ poly ) ; echo " Sign ▁ of ▁ polynomial ▁ is ▁ " , findSign ( $ poly , $ n , $ x ) ; ? >