• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ Vec_DP类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中Vec_DP的典型用法代码示例。如果您正苦于以下问题:C++ Vec_DP类的具体用法?C++ Vec_DP怎么用?C++ Vec_DP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: plotInterp

void plotInterp(const Vec_DP &xdata, const Vec_DP &ydata,
        const Vec_DP &interpx, const Vec_DP &interpy) {
    int pointnum = 100;
    double start = xdata[0];
    double end = xdata[xdata.size() - 1];

    myplot::data_set container;
    myplot::plot_data realPoints("k+2");
    myplot::plot_data interpPoints("r.");
    myplot::plot_data curve("c-2");
    for (int i = 0; i < pointnum; i++) {
        double x = start + ((double) i * (end - start)) / (pointnum - 1);
        double y, dy;
        NR::polint(xdata, ydata, x, y, dy);
        curve.add_point(x, y);
    }
    for (int i = 0; i < xdata.size(); i++) {
        realPoints.add_point(xdata[i], ydata[i]);
    }
    for (int i = 0; i < interpx.size(); i++) {
        interpPoints.add_point(interpx[i], interpy[i]);
    }
    container.push_back(curve);
    container.push_back(realPoints);
    container.push_back(interpPoints);
    myplot::plot(container);
}
开发者ID:plhrja,项目名称:C-NumeerisetMenetelmat,代码行数:27,代码来源:exc502.cpp


示例2: generateNoisyData

void generateNoisyData(Vec_DP& xdata, Vec_DP& ydata, Vec_DP& coeffs, double low, double high){
    for (int i = 0; i < coeffs.size(); i++) {
        coeffs[i] = rdm(low, high);
    }
    for (int i = 0; i < xdata.size(); i++) {
        ydata[i] = (coeffs[0]*pow(xdata[i],2) + coeffs[1]*xdata[i] + coeffs[2]) * rdm(0.8, 1.2);
    }
}
开发者ID:plhrja,项目名称:C-NumeerisetMenetelmat,代码行数:8,代码来源:exc401.cpp


示例3: runtime_error

Vec_DP operator-(Vec_DP const& a, Vec_DP const& b) {
    if (a.size() != b.size())
        throw runtime_error("Dimensions mismatch in vector subtraction!");
    Vec_DP x(a.size());
    for (int i = 0; i < a.size(); i++) {
        x[i] = a[i] - b[i];
    }
    return x;
}
开发者ID:lybeck,项目名称:NuMe,代码行数:9,代码来源:w9e1.cpp


示例4: spline_interp

void spline_interp(Vec_DP const& xdata, Vec_DP const& ydata, double yp1, double ypn, Vec_DP const& x, Vec_DP& y) {
    Vec_DP y2(xdata.size());
    NR::spline(xdata, ydata, yp1, ypn, y2);
    for (int i = 0; i < x.size(); i++) {
        NR::splint(xdata, ydata, y2, x[i], y[i]);
    }

    double err, errx;
    get_error(x, y, err, errx);

    cout << "Maximum error in spline interpolation: " << err << ", at x = " << errx << endl;
}
开发者ID:lybeck,项目名称:NuMe,代码行数:12,代码来源:w5e1.cpp


示例5: poly_interp

void poly_interp(Vec_DP const& xdata, Vec_DP const& ydata, Vec_DP const& x, Vec_DP& y) {
    Vec_DP c(xdata.size());
    NR::polcoe(xdata, ydata, c);
    for (int i = 0; i < x.size(); i++) {
        y[i] = poly_val(x[i], c);
    }

    double err, errx;
    get_error(x, y, err, errx);

    cout << "Maximum error in polynomial interpolation: " << err << ", at x = " << errx << endl;
}
开发者ID:lybeck,项目名称:NuMe,代码行数:12,代码来源:w5e1.cpp


示例6: interp_spline_periodic

double interp_spline_periodic(const Vec_DP &xdata, const Vec_DP &ydata, double deriv,
        Vec_DP &interpx, Vec_DP &interpy, Vec_DP &error) {
    Vec_DP y2(xdata.size());
    NR::spline(xdata, ydata, deriv, deriv, y2);
    for (int i = 0; i < interpx.size(); i++) {
        double y, x = i * (M_PI / 200);
        NR::splint(xdata, ydata, y2, x, y);
        interpx[i] = x;
        interpy[i] = y;
        error[i] = abs(sin(x) - y);
    }
    return get_max_error(error);
}
开发者ID:plhrja,项目名称:C-NumeerisetMenetelmat,代码行数:13,代码来源:exc501.cpp


示例7: solve_system

void solve_system(Vec_DP xdata, Vec_DP ydata, Vec_DP zdata){
    Mat_DP A(xdata.size(), 3);
    Vec_DP b(xdata.size());
    for (int i = 0; i < xdata.size(); i++) {
        double x = xdata[i];
        double y = ydata[i];
        
        A[i][0] = x;
        A[i][1] = y;
        A[i][2] = 1;
        b[i] = zdata[i];
    }
    SVDsolve(A, b, coeffs);
}
开发者ID:plhrja,项目名称:C-NumeerisetMenetelmat,代码行数:14,代码来源:exc705.cpp


示例8: construct_data

void construct_data(Vec_DP &xdata, Vec_DP &ydata){
    for (int i = 0; i < xdata.size(); i++) {
        double x = i * (M_PI / 10);
        xdata[i] = x;
        ydata[i] = sin(x);
    }
}
开发者ID:plhrja,项目名称:C-NumeerisetMenetelmat,代码行数:7,代码来源:exc501.cpp


示例9: get_max_error

double get_max_error(const Vec_DP &error){
    double max = 0;
    for (int i = 0; i < error.size(); i++) {
        max = (error[i] > max) ? error[i] : max;
    }
    return max;
}
开发者ID:plhrja,项目名称:C-NumeerisetMenetelmat,代码行数:7,代码来源:exc501.cpp


示例10: poly_val

double poly_val(double x, Vec_DP const& c) {
    double y = c[0];
    for (int n = 1; n < c.size(); n++) {
        y += c[n] * pow(x, n);
    }
    return y;
}
开发者ID:lybeck,项目名称:NuMe,代码行数:7,代码来源:w5e1.cpp


示例11: subst

Vec_DP subst(Vec_DP const& w) {
    if (w.size() != 2)
        throw runtime_error("Wrong dimension for input in subst!");
    Vec_DP x(2);
    x[0] = -2 + 2.8 * pow(sin(w[0]), 2);
    x[1] = w[1];
    return x;
}
开发者ID:lybeck,项目名称:NuMe,代码行数:8,代码来源:w11e2.cpp


示例12: constructData_B

void constructData_B(Vec_DP &xdata, Vec_DP &ydata) {
    double ylow = -10;
    double yhigh = 10;
    for (int i = 0; i < xdata.size(); i++) {
        xdata[i] = i + 1;
        ydata[i] = rdm(ylow, yhigh);
    }
}
开发者ID:plhrja,项目名称:C-NumeerisetMenetelmat,代码行数:8,代码来源:exc502.cpp


示例13: interp

void interp(const Vec_DP &xdata, const Vec_DP &ydata,
        Vec_DP &interpx, Vec_DP &interpy, Vec_DP &error) {
    for (int i = 0; i < interpx.size(); i++) {
        double y, errory, x = 2 + i * 0.25;
        NR::polint(xdata, ydata, x, y, errory);
        interpx[i] = x;
        interpy[i] = y;
        error[i] = errory;
    }
}
开发者ID:plhrja,项目名称:C-NumeerisetMenetelmat,代码行数:10,代码来源:exc502.cpp


示例14: GSsolve_iter

void GSsolve_iter(Mat_DP &a, Vec_DP &b, Vec_DP &x, Vec_DP &xold) {
    int i, j, rows = a.nrows();
    if ((rows != a.ncols()) || (rows != b.size()) ||
            (rows != x.size()) || (rows != xold.size())) {
        cout << "Argument error in GaussSeidel_iter\n" << endl;
        abort();
    }

    double s;
    for (i = 0; i < rows; i++) {
        s = 0;
        for (j = 0; j < rows; j++) {
            s += (j <= i - 1) ? a[i][j] * x[j] :
                    (j >= i + 1) ? a[i][j] * xold[j] : 0;
        }
        xold[i] = x[i];
        x[i] = (b[i] - s) / a[i][i];
    }
}
开发者ID:plhrja,项目名称:C-NumeerisetMenetelmat,代码行数:19,代码来源:exc402.cpp


示例15: interp_polint

double interp_polint(const Vec_DP &xdata, const Vec_DP &ydata,
        Vec_DP &interpx, Vec_DP &interpy, Vec_DP &error) {
    for (int i = 0; i < interpx.size(); i++) {
        double y, errory, x = i * (M_PI / 200);
        NR::polint(xdata, ydata, x, y, errory);
        interpx[i] = x;
        interpy[i] = y;
        error[i] = abs(sin(x) - y);
    }
    return get_max_error(error);
}
开发者ID:plhrja,项目名称:C-NumeerisetMenetelmat,代码行数:11,代码来源:exc501.cpp


示例16: math_deriv

void MATHEMATICS::math_deriv(Vec_DP &v1, Vec_DP v0, Vec_DP v2, double t0, double t2) {
	
	int n=v1.size();

	for (int i=0; i<n; i++) {

		v1[i]=(v2[i]-v0[i])/(t2-t0);

	}


}
开发者ID:dancleather,项目名称:FreeBody,代码行数:12,代码来源:math_deriv.cpp


示例17: get_error

void get_error(Vec_DP const& x, Vec_DP y, double& maxerr, double& errx) {
    maxerr = -INFINITY;
    double yy, err;
    for (int i = 0; i < x.size(); i++) {
        yy = sin(x[i]);
        err = abs(y[i] - yy);
        if (err > maxerr) {
            maxerr = err;
            errx = x[i];
        }
    }
}
开发者ID:lybeck,项目名称:NuMe,代码行数:12,代码来源:w5e1.cpp


示例18: math_vecmag

double MATHEMATICS::math_vecmag(Vec_DP a) {
	
	double c=0;
	int x=a.size();
	
	for(int i=0; i<x; i++) {
		c+=a[i]*a[i];		
	}
	
	c=sqrt(c);

	return c;
}
开发者ID:dancleather,项目名称:FreeBody,代码行数:13,代码来源:math_vecmag.cpp


示例19: construct_A

void construct_A(Mat_DP& A, Vec_DP& xdata){
    Vec_DP sums(4);
    for (int i = 0; i < sums.size(); i++) {
        sums[i] = 0;
    }
    for (int i = 0; i < xdata.size(); i++) {
        sums[0] += xdata[i]; 
        sums[1] += pow(xdata[i], 2); 
        sums[2] += pow(xdata[i], 3); 
        sums[3] += pow(xdata[i], 4); 
    }
    
    A[0][0] = sums[3];
    A[0][1] = sums[2];
    A[0][2] = sums[1];
    A[1][0] = sums[2];
    A[1][1] = sums[1];
    A[1][2] = sums[0];
    A[2][0] = sums[1];
    A[2][1] = sums[0];
    A[2][2] = xdata.size();
}
开发者ID:plhrja,项目名称:C-NumeerisetMenetelmat,代码行数:22,代码来源:exc401.cpp


示例20: construct_b

void construct_b(Vec_DP& b, Vec_DP& xdata, Vec_DP& ydata){
    Vec_DP sums(3);
    for (int i = 0; i < sums.size(); i++) {
        sums[i] = 0;
    }
    for (int i = 0; i < xdata.size(); i++) {
        sums[0] += ydata[i] * pow(xdata[i], 2); 
        sums[1] += ydata[i] * xdata[i]; 
        sums[2] += ydata[i]; 
    }
    
    b[0] = sums[0];
    b[1] = sums[1];
    b[2] = sums[2];
}
开发者ID:plhrja,项目名称:C-NumeerisetMenetelmat,代码行数:15,代码来源:exc401.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ Vec_IO_DP类代码示例发布时间:2022-05-31
下一篇:
C++ VecType类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap