NOIP2001 three-time equation solution [derivative + Newton iterative method]

Source: Internet
Author: User

Title Description

Tangible such as: ax3+bx2+cx+d=0 such a one-dimensional three-time equation. The coefficients of each of the equations (A,b,c,d are real) are given, and the equation has three different real roots (the range of the roots between 100 to 100), and the absolute value of the difference between root and root is >=1. It is required to output these three real roots (spaces between root and root) in the same row from small to large, and accurate to 2 digits after the decimal point.

Hint: Remember equation f (x) = 0, if there are 2 numbers x1 and x2, and x1<x2,f (x1) *f (x2) <0, then there must be a root between (X1,X2).

Input/output format

Input format:

One row, 4 real a,b,c,d.

Output format:

One line, three real roots, and accurate to 2 digits after the decimal point.

Input and Output Sample input example # #:
1-5-4 20
Sample # # of output:
-2.00 2.00 5.00

Data size is too small to be casual violence

But in order to prove that I have been studying calculus for a few days, using an advanced method
First f (x) =ax3+bx2+cx+d derivative get df/dx=3ax2+2bx+c
Find the 0 point of the derivative (that is, the two-time function to find the root formula) to get the maximum value of f (x).
There must be an F (x) 0 point for the three intervals consisting of the maximum points, and the 0 points can be obtained by Newton iterative method.
Newton's iterative method is the constant use of a point tangent to fit the curve, the derivative of that point is the tangent slope

And so on, we can get an iterative method to find 0 points of the higher order function:
To find the n-th function 0 points, need the extreme points to divide the interval, it is necessary to find its derivative (n-1 function) of 0 points, sequentially iterate to n=2 directly through the formula (of course n=3 or 4 can also)
The final complexity depends on the complex reading of the 0-point algorithm.
No one seems to have published it, so it's called Candy iterative method .
But does this have an advantage over the three-part approach to extremum?


////main.cpp//unary three-time equation////Created by Candy on 2016/12/10.//copyright©2016 year Candy. All rights reserved.//#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespacestd;Const Doubleeps=1e-3;DoubleA,b,c,d;inlineDoubleFDoublex) {return((a*x+b) *x+c) *x+D;} InlineDoubledfDoublex) {return(3*a*x+2*B) *x+C;}DoubleSolDoubleLDoubleR) {//printf ("Sol%lf%lf\n", l,r);    intstep= -;Doublex= (L+R)/2;  while(step--) {x=x-f (x)/DF (x); }    returnx;}intMainintargcConst Char*argv[]) {scanf ("%LF%LF%LF%LF",&a,&b,&c,&d); DoubleP1= (-sqrt (b*b-3*A*C)-B)/(3*a), p2= (+sqrt (b*b-3*A*C)-B)/(3*a); printf ("%.2f%.2f%.2f\n", Sol (- -, p1), Sol (P1,P2), Sol (P2, -)); return 0;}



NOIP2001 three-time equation solution [derivative + Newton iterative 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.