Because this method itself is math problems do not discuss here also do not need to discuss, to enter the theme of our programming,
Remember this formula: x=x0 (x0) - f/f '(x0). We make the x1=f (x0), x2=f' (x0), so to write clear and concise,
Steps: (1) any near 1 to find a real number as the initial value of x0, such problem, we take x=1, let x0=x, namely x0=1.
(2) with the initial value x0 into the equation to calculate f (x0) and f '(x0). And the x1 and x2;
(3) into the core formula to calculate the x=x0 (x0) - f/f '(x0) the value of the
(4) are replaced with new x the original x0, preparing for the next iteration,
(5) if | x - x0 | & gt; E=1-5; Is to continue the iteration, otherwise turn (6).
(6) the x which is far equation ax ^ 3 + bx cx + d=0 ^ 2 + the root of the output,
HTML code is as follows: (after VS2008 and correct testing input output: 1, 2, 3, 4-1.65)
#include
#include
Double getRes (double a, b double, double c, double d) {
Doublex=1, x0, x1, x2,
Do {
X0=x;
X1=a * * * x x x + b * x * x * x + c + d.
X2=3 * a * b * x * x + 2 * x + c;
X=x0 - x1 and x2;
} while (fabs (x - x0) & gt; E=1-5);
return x;
}
Int main () {
Doublea, b, c, d;
The scanf (" % % lf, lf and lf %, % lf ", & amp; A, & amp; B, & amp; C., & amp; D);
Printf (" x=% 2 lf \ n ", getRes (a, b, c, d));
return 0;
}
CodePudding user response:
Baidu search relevant keywords,CodePudding user response:
There should be four solutionsCodePudding user response:
The