题目链接:uva 10428 - The Roots
题目大意:给定一个n次一元多项式,求出所有解。
解题思路:牛顿迭代法,对于任意给定x,通过牛顿迭代法可以趋近距离x最近的解x0。每次找到一个解后,用多项式除法除掉x−x0后继续求解。
牛顿迭代法:xi+1=xi−f(x)f′(x)
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 10;
int N;
double a[maxn];
void div (double* f, double x, int n) {
f[n+1] = 0;
for (int i = n; i >= 0; i--)
f[i] += f[i+1] * x;
for (int i = 0; i < n; i++)
f[i] = f[i+1];
}
double func (double* f, double x, int n) {
double ret = 0, u = 1;
for (int i = 0; i <= n; i++) {
ret += f[i] * u;
u *= x;
}
return ret;
}
double newton (double* f, int n) {
double fd[maxn];
for (int i = 0; i < n; i++)
fd[i] = f[i+1] * (i+1);
double x = -100;
for (int i = 0; i < 100; i++)
x -= func(f, x, n) / func(fd, x, n-1);
return x;
}
void solve () {
for (int i = 0; i < N; i++) {
double x = newton(a, N-i);
printf(" %.4lf", x);
div(a, x, N-i);
}
}
int main () {
int cas = 1;
while (scanf("%d", &N) == 1 && N) {
for (int i = N; i >= 0; i--)
scanf("%lf", &a[i]);
printf("Equation %d:", cas++);
solve();
printf("\n");
}
return 0;
}
分享到:
相关推荐
摘要:牛顿迭代法是《数值分析》这门课程中一个重要的计算方法和思想。这次的课程设计是通过在学习中所学习到的牛顿迭代的方法的思想计算方程:求方程 x3+x2-3x-3=0 在1.5附近根。并通过VISUALC++编译程序计算出方程...
方程求根 inv - 逆矩阵 roots - 多项式的根newton - 牛顿迭代法解非线性方程
13623-calculate-roots-of-chebyshev-polynomials.zip.zip
拉格朗日插值法方程求根inv - 逆矩阵eig - 特征值和特征向量roots - 多项式的根fzero - 一元函数零点fsolve - 非线性方程组solve - 符号方程解*newton - 牛顿迭代法解非线性方程*spgs - 大型稀疏方程组Gauss-Seidel...
React本源 <App> <---- original app <YourView1> <---- your view ...import Roots from 'react-native-roots' ; // add root view Roots . add ( 'loading' , ( < ActivityIndic
TPM 相关技术规范
fileSystems-roots.js
r = roots(c) returns a column vector whose elements are the roots of the polynomial c. Row vector c contains the coefficients of a polynomial, ordered in descending powers. If c has n+1 components, ...
The roots of an arbitrary function or equation are calculated
“根血腥根”低音分区 使用构建。 输出可在下载。 此页面上的所有内容均为原始作品的版权所有者的财产。
% 方程求根 % inv - 逆矩阵 % roots - 多项式的根 % fzero - 一元函数零点 % fsolve - 非线性方程组 % solve - 符号方程解 % *newton - 牛顿迭代法解非线性方程
自动部署 WordPress 和 Roots 对于本地 Ubuntu 14.04 开发环境。 需要 。 注意:我对 BASH 脚本很陌生,所以请仔细阅读此代码。 它对我们很有效,但使用风险自负! ##它能做什么## 在/var/www为站点创建一个新...
Designed to achieve two goals: to add a large number of words to your permanent working vocabulary, and to teach the most useful of the classical word-building roots to help you continue expanding ...
The American spymaster who built the Office of Strategic Services in the World War Ⅱ and later laid the roots for the CIA was fascinated with information. Donovan believed in using whatever tools ...
var roots = require ( 'quadratic-roots' ) roots ( 0 , 0 , 0 ) // --> [] roots ( 0 , 0 , 6 ) // --> [] roots ( 0 , 2 , 6 ) // --> [-3] roots ( 1 , 1 , - 12 ) // --> [-4,3] roots ( 1 , - 4 ...
Designed to achieve two goals: to add a large number of words to your permanent working vocabulary, and to teach the most useful of the classical word-building roots to help you continue expanding ...
ethylene in the control of sprouting of sweetpotato roots, however, is not known. The aim of this study was to investigate the role of ethylene in control of sprouting in sweetpotato roots by ...
Matlab下求非线性方程组的根同样适合于线性方程组-matlab_roots_for_nonlinear_equations.zip 以前给过一些程序,不过这个是我审核过的,最好最强大的求根程序。 使用Matlab,对非线性方程组求根,当然,既然非...
非单调迭代根的一些进展,张伟年,,寻找非单调函数的迭代根一直被认为是一个困难的问题。80年代张景中、杨路讨论了一类叫做PM函数的非单调函数的连续迭代根。对这类�
Exponents, logs and square roots Truncating Integers "Random Numbers The Lotto script String Functions The Length function The Index Function The Substr function GAWK's Tolower and Toupper ...