本文整理汇总了C++中vec_RR::SetLength方法的典型用法代码示例。如果您正苦于以下问题:C++ vec_RR::SetLength方法的具体用法?C++ vec_RR::SetLength怎么用?C++ vec_RR::SetLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vec_RR
的用法示例。
在下文中一共展示了vec_RR::SetLength方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: negate
void negate(vec_RR& x, const vec_RR& a)
{
long n = a.length();
x.SetLength(n);
long i;
for (i = 0; i < n; i++)
negate(x[i], a[i]);
}
示例2: sub
void sub(vec_RR& x, const vec_RR& a, const vec_RR& b)
{
long n = a.length();
if (b.length() != n) Error("vector sub: dimension mismatch");
x.SetLength(n);
long i;
for (i = 0; i < n; i++)
sub(x[i], a[i], b[i]);
}
示例3: mul
void mul(vec_RR& x, const vec_RR& a, const RR& b_in)
{
RR b = b_in;
long n = a.length();
x.SetLength(n);
long i;
for (i = 0; i < n; i++)
mul(x[i], a[i], b);
}
示例4: add
void add(vec_RR& x, const vec_RR& a, const vec_RR& b)
{
long n = a.length();
if (b.length() != n) LogicError("vector add: dimension mismatch");
x.SetLength(n);
long i;
for (i = 0; i < n; i++)
add(x[i], a[i], b[i]);
}
示例5: VectorCopy
void VectorCopy(vec_RR& x, const vec_RR& a, long n)
{
if (n < 0) Error("VectorCopy: negative length");
if (NTL_OVERFLOW(n, 1, 0)) Error("overflow in VectorCopy");
long m = min(n, a.length());
x.SetLength(n);
long i;
for (i = 0; i < m; i++)
x[i] = a[i];
for (i = m; i < n; i++)
clear(x[i]);
}
示例6: mul_aux
static
void mul_aux(vec_RR& x, const mat_RR& A, const vec_RR& b)
{
long n = A.NumRows();
long l = A.NumCols();
if (l != b.length())
Error("matrix mul: dimension mismatch");
x.SetLength(n);
long i, k;
RR acc, tmp;
for (i = 1; i <= n; i++) {
clear(acc);
for (k = 1; k <= l; k++) {
mul(tmp, A(i,k), b(k));
add(acc, acc, tmp);
}
x(i) = acc;
}
}
示例7: solve
void solve(RR& d, vec_RR& X,
const mat_RR& A, const vec_RR& b)
{
long n = A.NumRows();
if (A.NumCols() != n)
Error("solve: nonsquare matrix");
if (b.length() != n)
Error("solve: dimension mismatch");
if (n == 0) {
set(d);
X.SetLength(0);
return;
}
long i, j, k, pos;
RR t1, t2;
RR *x, *y;
mat_RR M;
M.SetDims(n, n+1);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++)
M[i][j] = A[j][i];
M[i][n] = b[i];
}
RR det;
set(det);
RR maxval;
for (k = 0; k < n; k++) {
pos = -1;
clear(maxval);
for (i = k; i < n; i++) {
abs(t1, M[i][k]);
if (t1 > maxval) {
pos = i;
maxval = t1;
}
}
if (pos != -1) {
if (k != pos) {
swap(M[pos], M[k]);
negate(det, det);
}
mul(det, det, M[k][k]);
// make M[k, k] == -1
inv(t1, M[k][k]);
negate(t1, t1);
for (j = k+1; j <= n; j++) {
mul(M[k][j], M[k][j], t1);
}
for (i = k+1; i < n; i++) {
// M[i] = M[i] + M[k]*M[i,k]
t1 = M[i][k];
x = M[i].elts() + (k+1);
y = M[k].elts() + (k+1);
for (j = k+1; j <= n; j++, x++, y++) {
// *x = *x + (*y)*t1
mul(t2, *y, t1);
add(*x, *x, t2);
}
}
}
else {
clear(d);
return;
}
}
X.SetLength(n);
for (i = n-1; i >= 0; i--) {
clear(t1);
for (j = i+1; j < n; j++) {
mul(t2, X[j], M[i][j]);
add(t1, t1, t2);
}
sub(t1, t1, M[i][n]);
X[i] = t1;
}
d = det;
}