Algorithm question 2 (a solid root of the high equation 2x ^ 4-4x ^ 3 + 6x ^ 2-8x-8 = 0)

Source: Internet
Author: User

Obtain a solid root of the high equation 2x ^ 4-4x ^ 3 + 6x ^ 2-8x-8 = 0 (accuracy requirement: 10 ^-3)

Algorithm analysis is as follows: There are many real-root algorithms for High-Level equations. Here we introduce a kind of bipartite method.

If the higher-order equation f (x) is set to 0, a real root algorithm is obtained using the bipartite method as follows:

1. input the initial values X1 and X2 and calculate their corresponding function values Y1 = f (X1), y2 = f (X2 ). if the numbers Y1 and Y2 are the same, there is no real root to re-input between X1 and X2; otherwise there is a real root between X1 and X2, which is converted to step 2.

2. Calculate the intermediate position X = (X1 + x2)/2

3. Calculate the X-point function value Y1 = f (X1), Y = f (x ). If the function value is y = 0, the algorithm ends. X is a solid root of the higher order worker. Otherwise, it is converted into four steps.

4. If the function values Y and Y1 are the same, it indicates that the real root is between X1 and X2, then X1 = x is converted to 2nd. Otherwise, it indicates that the real root is between X1 and X, x2 = x, convert to 2nd

# Include <stdio. h> <br/> # include <math. h>/* The program uses the function FABS () */<br/> int main () <br/> {<br/> float x1, x2, X, y1, Y2, Y; <br/> DO <br/>{< br/> printf ("Enter do"); <br/> scanf ("% F, % F ", & X1, & x2 ); <br/> Y1 = 2 * X1 * X1 * X1 * x1-4 * X1 * X1 * X1 + 6 * X1 * x1-8 * x1-8; <br/> Y2 = 2 * X2 * X2 * X2 * x2-4 * X2 * X2 * X2 + 6 * X2 * x2-8 * x2-8; <br/> printf ("Y1 * y2 = % d Y1 * Y2> 0: % d", Y1 * Y2, (Y1 * Y2)> 0 ); <br/>}while (Y1 * Y2)> 0); <br/> while (1) /* This is an infinite loop under a constant condition */<br/> {<br/> X = (X1 + x2)/2; <br/> Y = 2 * x * X-4 * x + 6 * x * x-8 * x-8; <br/> Y1 = 2 * X1 * X1 * X1 * x1-4 * X1 * X1 * X1 + 6 * X1 * x1-8 * x1-8; <br/> If (FABS (y) <1e-5) break;/* find the root and force exit */<br/> else if (y * Y> 0) x1 = x; <br/> else X2 = x; <br/>}< br/> printf ("x = % F/N", X ); /* This equation has a solid root of 2.0 between 0 and 10 */<br/>}< br/> 

 

 

 

 

 

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.