//1DoublePoly (DoubleA[],DoubleXintdegree) { Long inti; Doubleresult = a[0]; DoubleXPWR =x; for(i =1; I i) {Redsult+ = a[i] *XPWR; XPWR= x *XPWR; } returnresult;} // horner ' s method double polyh (double a[], 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
The Horner algorithm is a fast algorithm named after William George Horner, a British mathematician. In fact, it has been used by Paolo ruffini before. Chinese mathematician Qin Jiuyi proposed this algorithm more than William George Horner 600 years earlier.
P (x) is a polynomial:
We want to calculate the polynomial value p (x0) when X is a special value x0 )
Description
Horner finds any polynomial p (x) = A0 + A1 * x +... + An * x ^ N can be converted
P (x) = A0 + x * (A1 + x * (A2 +... + X * (an-1 + an * X )...)) To improve the computing efficiency of the computer.
Given the maximum n of p (x), the coefficients a0, A1,..., An, and variable X. Use the Horner method to obtain the polynomial p (x) val
Horner Rule is a common Rule, but there are not many related information on the Internet. I mainly found two.1. http://blog.csdn.net/lwj1396/archive/2008/07/18/2669993.aspx
2. http://flynoi.blog.hexun.com/31272178_d.htmlIn the second article, the reason for the emergence of the Horna law is described: it provides an efficient method for polynomial evaluation."The most common algorithm for polynomial evaluat
+ 7Although there is no problem with this writing method, most beginners do not realize the true meaning of this expression.
It actually meansX * x + (double) 2 * x + (double) 3 * x + (double) 8 * x + (double) 7If you are not clear about data types, you will never learn programming well.X + 2 x + 3 x + 8 x + 7If the true meaning of such an expression is true, try not to write an expression that combines the integer type and the floating point type. F
Generate random numbersPackage Cn.xf.algorithm.ch02;import Java.util.arraylist;import java.util.list;/** * Production random number * @author xiaof * */public clas s random {/** * produces a sequence of random numbers * @param n generates n columns * @param m data between 0 and m-1 * @param seed random Initial seed * @param a parameter * @param b parameter * @re Turn */public static list Random coefficient of valueValue evaluationPackage Cn.xf.algorithm.ch06changerule;import Java.util.arraylis
Polynomial evaluationSuppose there is a sequence of n+2 real a0,a1,..., An and X, to find the polynomialP_NX = a_nx^n + a_n-1x^n-1 + ... + a_1x + a_0;You need multiplication: n+n-1 + ... +2+1 = n (n+1)/2Need addition: NVisible algorithm efficiency is O (n^2)and P_nx = ((... (((((a_n) x + a_n-1) x + a_n-2) x + a_n-3) ...) X + a_1x) + a_0So the idea:p_0x = A_np_1x = xp_0x + a_n-1p_2x = xp_2x + a_n-2......P_NX = xp_n-1x + a_0Complexity of Time:Make t (n) The sum of the addition and multiplication r
Horner (Horner) rule is to use the least Multiplication Algorithm, calculate the polynomial A (x) = anxn + an-1xn-1 +... + a1x + a0 at x0 value. This rule is a (x0) = (... (anx0 + an-1) x0 +... + A1) x0 + a0 ). Use the Horna rule to write C LanguageProgramEvaluate the polynomial.
// Use recursion to evaluate
Generate random numbers
Package Cn.xf.algorithm.ch02;import Java.util.arraylist;import java.util.list;/** * Production random number * @author xiaof * */public clas s random {/** * produces a sequence of random numbers * @param n generates n columns * @param m data between 0 and m-1 * @param seed random Initial seed * @param a parameter * @param b parameter * @re Turn */public static list
Random coefficient of value
Value evaluation
Package Cn.xf.algorithm.ch06changerule;import Java.util.a
-- Calculation Method of the error range in the previous example of the project (using the method of exhaustion, also known as the stupid method, also known as the yugong mountain migration method, or the yugong war, the smart Olay method)
Declare @ const_a decimal (8,
Method rewriting and method overloading; Method Rewriting Method Overloading
Inheritance and polymorphism are the characteristics of object-oriented programming. Using inheritance, you can create a subclass based on a parent class. This subclass not only has the existing attributes and methods of the parent class, but
First, virtual method (virtual method)The virtual keyword is used to decorate a method in a base class. There are two things you can do with virtual:Scenario 1: The virtual method is defined in the base class, but the virtual method is not overridden in the derived class. In
1 . The first argument of an instance method instance method must be "self", and the instance method can only be invoked through a class instance, at which point "Self" represents the instance itself . the properties of an instance can be accessed directly through "self" .
class Person (object):
tall = 180
Hobbies = []
def __init__ (self, Name, age,we
Partial method Gu Mingsi is part of the method, incomplete, when the IDE compiles, all parts of the method will be loaded into a unified compilation, if the partial method is not implemented, the compiler will not, compile them.Restrictions on local types(1) Local types are only applicable to classes, interfaces, struc
ObjectiveBefore the teacher talked about the selection method and bubbling method, and then mentioned the insertion method and sorting method, today did a small demo, compared to the efficiency of the four methods, of course, see a lot of Daniel also blog, in fact, the algorithm also designed the time complexity and sp
In JS
Code Write function FN () {} Or var fn = function () {} and so on, you can understand it as an object, of course, there are arrays and so on.
Before understanding object-oriented, let's take a look at the following.1. Call of object MethodsThe function written at the outermost layer of JS can also be understood as a method of window objects. The Defined variables can also be called an attribute of the window object. For example:
[JavaS
In project development, we all have this experience, that is, when adding a table, the corresponding increase in Java classes, in the Java class, there are a number of common methods, including: Equals (), Hashcode (), toString (), CompareTo () These four methods, For beginners who just touch Java, for this piece can not be more in-depth understanding, just the simple meaning of copy and paste, and not very good to understand.Now borrow this time to talk about these methods. equals: used when co
What is the difference between the sleep () method of the thread class and the Wait () method of the object that allows the thread to pause execution?The Sleep () method (Hibernate) is a static method of the thread class (threads), which causes the current thread to pause execution for a specified time, giving the exec
Instance method, class method, and static method, and instance method static
When learning python code, we can see that the first parameter in some class methods is cls and the first parameter is self. After understanding it, python does not limit the name of the first parameter in the class, it can be self or cls, but
The PHP method, Asp method, MsSQL method, and MySQL method for converting an IP address to an integer. First, we need to first understand the principle of converting an IP address to an integer (in strict terms, it should be a long integer ~ [Conversion principle]: assume that the IP address is w. x. y. z, then the IP
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.