NANA
polynomialevaluation.cpp
1#include "..\include\math\polynomialevaluation.hpp"
2
3
4namespace NANA {
5namespace MATH {
6
7double PolynomialEvaluation2D(const Matrix& mat, double x, double y, int n) {
8 NA_Assert(n == mat.cols());
9 double ret, s, xx;
10 int m = mat.rows();
11 ret = 0.0;
12 xx = 1.0;
13 for (int i = 0; i < m; ++i) {
14 s = mat[i][n - 1] * xx;
15 for (int j = n - 2; j >= 0; --j) {
16 s = s * y +mat[i][j] * xx;
17 }
18 ret += s;
19 xx *= x;
20 }
21
22 return ret;
23}
24
25
26
27}
28}
简单矩阵类
Definition: matrix.h:31
int rows() const
获取矩阵的行数
Definition: matrix.cpp:58
int cols() const
获取矩阵的列数
Definition: matrix.cpp:54
#define NA_Assert(expr)
当表达式非法,抛出异常
Definition: error.h:56
double NA_API PolynomialEvaluation2D(const Matrix &mat, double x, double y, int n)
二维多项式求值