简体   繁体   English

我的范德蒙德矩阵程序哪里出错了?

[英]Where did my Vandermonde-matrix prgram go wrong?

Screenshot of the error code I am trying to figure out why my program is not working the way it should. 错误代码的屏幕截图,我试图弄清楚为什么我的程序无法正常运行。 It is a program that is supposed to create a Vandermonde-matrix but it get is the last digits wrong and I really do not see why that`s happening. 这是一个应该创建Vandermonde矩阵的程序,但最后一位数字是错误的,我真的不知道为什么会这样。 I have gone through it manually (you know, checking what the computer is doing and writing it down on a paper) and I really do not see where it is going worng. 我已经手动进行了检查(您知道,检查计算机在做什么并将其记录在纸上),但我真的看不到它要去哪里。

Thank you in advance! 先感谢您!

#include <iostream>
#include <vector>
#include <math.h>


int main ()
{
    int n, m;
    std::cin >> m;
    std::cin >> n;

    double x[m];

    for (int l = 0; l < m; l++) //fill in x-es
    {
        double f;
        std::cin >> f;
        x[l] = f;
    }


    std::vector<std::vector<double> > mat ( n , std::vector<double>( m, 0));

    for ( int i = 0; i < m; i++) //creat matrix
        for (int j = 0; j < n; j++)
            {
                mat [i][j] = pow(x[i] , j);
            }

    for (int i = 0 ; i < m ; ++i) 
    {
        for (int j = 0 ; j < n ; ++j)
            std::cout << mat [ i ] [ j ] << " " ;

                std::cout << "\n" ;
    }

    return 0;
}

Replace std::vector<std::vector<double> > mat ( n , std::vector<double>( m, 0)); 替换std::vector<std::vector<double> > mat ( n , std::vector<double>( m, 0)); with std::vector<std::vector<double> > mat ( m , std::vector<double>( n, 0)); std::vector<std::vector<double> > mat ( m , std::vector<double>( n, 0));

It will work fine 会很好的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM