当前位置: 首页>>代码示例>>C++>>正文


C++ DoubleVector::length方法代码示例

本文整理汇总了C++中DoubleVector::length方法的典型用法代码示例。如果您正苦于以下问题:C++ DoubleVector::length方法的具体用法?C++ DoubleVector::length怎么用?C++ DoubleVector::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DoubleVector的用法示例。


在下文中一共展示了DoubleVector::length方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Gradient

void IGradient::Gradient(const RnFunction *f, double step, const DoubleVector &x, DoubleVector &g)
{
    double h = step;
    for (unsigned int i=0; i<g.length(); i++)
    {
        double cx = x[i];
        const_cast<DoubleVector&>(x)[i] = cx - h;
        double f1 = f->fx(x);
        const_cast<DoubleVector&>(x)[i] = cx + h;
        double f2 = f->fx(x);
        const_cast<DoubleVector&>(x)[i] = cx;
        g[i] = (f2 - f1) / (2.0 * h);
    }
}
开发者ID:hvugar,项目名称:num_methods,代码行数:14,代码来源:function.cpp

示例2: calculateGX

void HeatControl2Delta::gradient(const DoubleVector& x, DoubleVector& g)
{
    px = &x;
    DoubleMatrix u;
    IParabolicEquation2D::calculateMVD(u, h1, h2, ht, N1, N2, M, a1, a2);

    pu = &u;
    DoubleCube psi;
    IBackwardParabolicEquation2D::calculateMVD(psi, h1, h2, ht, N1, N2, M, a1, a2);

    for (unsigned int i=0; i<g.length(); i++) g[i] = 0.0;

    for (unsigned int k=M; k!=(unsigned int)0-1; k--)
    {
        calculateGX(x, psi.matrix(k), g, k);
        //calculateGF(x, psi[k], g, k);
    }

    //    for (unsigned int k=0; k<=M; k++)
    //    {
    //        unsigned int i1 = (unsigned int)round(E[0]/h1);
    //        unsigned int j1 = (unsigned int)round(E[1]/h2);
    //        g[0*(M+1)+k] = -psi[k][j1][i1] + 2.0*alpha*(v[0*(M+1)+k] - v1(k*ht));

    //        unsigned int i2 = (unsigned int)round(E[2]/h1);
    //        unsigned int j2 = (unsigned int)round(E[3]/h2);
    //        g[1*(M+1)+k] = -psi[k][j2][i2] + 2.0*alpha*(v[1*(M+1)+k] - v2(k*ht));

    //        unsigned int i3 = (unsigned int)round(E[4]/h1);
    //        unsigned int j3 = (unsigned int)round(E[5]/h2);
    //        g[2*(M+1)+k] = -psi[k][j3][i3] + 2.0*alpha*(v[2*(M+1)+k] - v3(k*ht));
    //    }

    psi.clear();
    //    IGradient::Gradient(this, 0.0001, x, g);
}
开发者ID:hvugar,项目名称:num_methods,代码行数:36,代码来源:heatcontrol2delta.cpp

示例3: gradient

void IFunctional::gradient(const DoubleVector &pv, DoubleVector &g) const
{
    IFunctional *ifunc = const_cast<IFunctional*>(this);
    unsigned int L = mTimeDimension.sizeN();
    double ht = mTimeDimension.step();

    ifunc->fromVector(pv, ifunc->mParameter);
    forward->setParameter(mParameter);
    backward->setParameter(mParameter);

    DoubleMatrix u;
    DoubleMatrix p;

    vector<ExtendedSpaceNode2D> u_info;
    forward->calculateMVD(u, u_info, true);

    backward->u = &u;
    backward->U = &ifunc->U;
    backward->info = &u_info;
    vector<ExtendedSpaceNode2D> p_info;
    backward->calculateMVD(p, p_info, true);

    g.clear();
    g.resize(pv.length(), 0.0);
    unsigned int gi = 0;

    // k
    if (optimizeK)
    {
        for (unsigned int i=0; i<mParameter.Lc; i++)
        {
            ExtendedSpaceNode2D &pi = p_info[i];

            for (unsigned int j=0; j<mParameter.Lo; j++)
            {
                ExtendedSpaceNode2D &uj = u_info[j];

                double grad_Kij = 0.0;

                grad_Kij += 0.5 * (pi.value(0)+2.0*r*gpi(i,0,u_info)*sgn(g0i(i,0,u_info))) * (uj.value(0) - mParameter.z.at(i,j));
                for (unsigned int m=1; m<=L-1; m++)
                {
                    grad_Kij += (pi.value(m)+2.0*r*gpi(i,m,u_info)*sgn(g0i(i,m,u_info))) * (uj.value(m) - mParameter.z.at(i,j));
                }
                grad_Kij += 0.5 * (pi.value(L)+2.0*r*gpi(i,L,u_info)*sgn(g0i(i,L,u_info))) * (uj.value(L) - mParameter.z.at(i,j));
                grad_Kij *= -ht;

                g[gi++] = grad_Kij + 2.0*regEpsilon*(mParameter.k.at(i,j) - mParameter0.k.at(i,j));
            }
        }
    }
    else
    {
        for (unsigned int i=0; i<mParameter.Lc; i++)
        {
            for (unsigned int j=0; j<mParameter.Lo; j++)
            {
                g[gi++] = 0.0;
            }
        }
    }

    // z
    if (optimizeZ)
    {
        for (unsigned int i=0; i<mParameter.Lc; i++)
        {
            ExtendedSpaceNode2D &pi = p_info[i];

            for (unsigned int j=0; j<mParameter.Lo; j++)
            {
                double grad_Zij = 0.0;

                grad_Zij += 0.5 * (pi.value(0)+2.0*r*gpi(i,0,u_info)*sgn(g0i(i,0,u_info))) * mParameter.k.at(i,j);
                for (unsigned int m=1; m<=L-1; m++)
                {
                    grad_Zij += (pi.value(m)+2.0*r*gpi(i,m,u_info)*sgn(g0i(i,m,u_info)))  * mParameter.k.at(i,j);
                }
                grad_Zij += 0.5 * (pi.value(L)+2.0*r*gpi(i,L,u_info)*sgn(g0i(i,L,u_info))) * mParameter.k.at(i,j);
                grad_Zij *= ht;

                g[gi++] = grad_Zij + 2.0*regEpsilon*(mParameter.z[i][j] - mParameter0.z[i][j]);
            }
        }
    }
    else
    {
        for (unsigned int i=0; i<mParameter.Lc; i++)
        {
            for (unsigned int j=0; j<mParameter.Lo; j++)
            {
                g[gi++] = 0.0;
            }
        }
    }

    // xi
    if (optimizeO)
    {
        for (unsigned int j=0; j<mParameter.Lo; j++)
//.........这里部分代码省略.........
开发者ID:hvugar,项目名称:num_methods,代码行数:101,代码来源:ifunctional.cpp


注:本文中的DoubleVector::length方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。