The calculation of polynomial and the evaluation of Horner polynomial method

Source: Internet
Author: User

//1DoublePoly (DoubleA[],DoubleXintdegree) {        Long inti; Doubleresult = a[0]; DoubleXPWR =x;  for(i =1; I <= degree; ++i) {Redsult+ = a[i] *XPWR; XPWR= x *XPWR; }          returnresult;}
 // horner ' s method  double  polyh (double  X. int   degree) { long  int   I;         double  result = A[degree];  for  (i = degree-1 ; I >= 0 ;        --i) {result  = A[i] + x * result;  return   result;}  

The same thing, recursion is more magical than iteration. From the code perspective, recursion has fewer additions and multiplication, so in terms of efficiency, recursion is more efficient than iteration ... The low.

Why is it? Assuming that the machine cat and the Fire shadow each episode has the same amount of information, then the inevitable fire shadow broadcast a set takes longer, why? Because the fire shadow each episode has the lengthy previously review, recalls, recalls, then recalls the time. One reason, each iteration is doing the same action, but the material is not the same; And each recursive to the previous steps again, so the first iteration and recursion efficiency difference is not obvious, but when the implementation of the more and more distant, the machine cat all the props out, the fire Shadow is also immersed in the memory of it.

Above.

The calculation of polynomial and the evaluation of Horner polynomial method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.