本文整理汇总了C++中ArrayXd::setLinSpaced方法的典型用法代码示例。如果您正苦于以下问题:C++ ArrayXd::setLinSpaced方法的具体用法?C++ ArrayXd::setLinSpaced怎么用?C++ ArrayXd::setLinSpaced使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayXd
的用法示例。
在下文中一共展示了ArrayXd::setLinSpaced方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GuassLobattoQaudrature
MatrixXd NumInt::GuassLobattoQaudrature(const int &N) {
int N0=N;
double a=1.0; double b=1.0;
double a1=2.0; double b1 = 2.0;
if (N0>=1)
{
N0=N0-2;
}
// Build the pointers
int* _N = &N0;
double* _a=&a; double* _b=&b;
double* _a1=&a1; double* _b1=&b1;
// Initial Guess - Chebyshev-Gauss-Lobatto points
ArrayXd xu;
xu.setLinSpaced(N0+2,0.0,N0+1);
ArrayXd x=-cos(xu/(N0+1)*M_PI);
// Allocate space for points and weights
VectorXd z = VectorXd::Zero(x.size());
VectorXd w = VectorXd::Zero(x.size());
double x0,x1,del; double* _x0 = &x0; double* _x1 = &x1;
double deps = std::numeric_limits<double>::epsilon();
for (int k=0; k<=x.size()-1; k++)
{
x0=x(k);
del=2.0;
while (fabs(del) > deps)
{
// Polynomial Deflation: Exclude the already determined roots
VectorXd s1 = x.head(k);
VectorXd ones = VectorXd::Constant(s1.size(),1);
double s = (ones.cwiseQuotient((x0-s1.array()).matrix())).sum();
// Compute Jacobi polynomial p(a,b)
JacobiPolynomials J(_N,_a,_b,_x0,false);
VectorXd p = J.getJacobiPolynomials();
// Compute Jacobi polynomial p(a+1,b+1) for derivative dp(a,b)
JacobiPolynomials J1(_N,_a1,_b1,_x0,false);
VectorXd p1 = J1.getJacobiPolynomials();
VectorXd dp=VectorXd::Zero(p1.size()); dp(0)=0;
// Compute derivative of Jacobi polynomial p(a,b)
for (int j=0; j<=*_N-1; j++)
{
dp(j+1) = 0.5*(*_a+*_b+j+2)*p1(j);
}
//Gauss-Lobatto points are roots of (1-x^2)*dp, hence
double nom = (1-x0*x0)*p(N0); double dnom = -2*x0*p(N0)+(1-x0*x0)*dp(N0);
del = - nom/(dnom-nom*s);
x1 = x0+del;
x0=x1;
}
z(k)=x1;
double a2=0; double b2=0; int N1=N0+1;
double* _a2=&a2; double* _b2=&b2; int* _N1 = &N1;
JacobiPolynomials J(_N1,_a2,_b2,_x1,false);
VectorXd p = J.getJacobiPolynomials();
w(k) = 2.0/((N1)*(N1+1)*p(N1)*p(N1));
}
// Store
Matrix<double,Dynamic,Dynamic> zw(N0+2,2);
zw.col(0)=z;
zw.col(1)=w;
return zw;
}