Anonymní profil Brabli – Programujte.com
 x   TIP: Přetáhni ikonu na hlavní panel pro připnutí webu

Anonymní profil Brabli – Programujte.comAnonymní profil Brabli – Programujte.com

 

Příspěvky odeslané z IP adresy 188.175.172.–

Brabli
C / C++ › No matching function for cal…
19. 12. 2015   #207425

Zdravím, nevím si rady. Jsem začátečník a k´d mi pše chybu, kterou jsem zatím nevyřešil. na řádku 14 "No matching function for call to?

//Gauss Elimination
#include<iostream>
#include<iomanip>
#include<math.h>
#include<fstream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
double d=0;

int pocet_radku(string filename)
{
    ifstream file;
    file.open(filename);

    int r = 0;
    string value;

    while(!file.eof())
    {getline(file, value, '\n');
    r++;
    }

    file.close();
    return r;
}



double **file_load(string filename, const unsigned int radky)
{
    ifstream file;
    unsigned int r, s;
    unsigned int sloupce = radky + 1;

    double **matice = new double*[radky];
    for(r = 0; r < radky; r++)
    {
        matice[r] = new double[sloupce];
    }

    file.open(filename);
    for(r = 0; r < radky; r++)
    {
        for(s = 0; s < sloupce; s++)
        {
            file >> matice[r][s];
        }
    }

    file.close();
    return matice;
}

void gaus (double **a, double *x,int n){
 int i=0;
 int j,k=0;
 for (i=0;i<n;i++)                    //Pivotisation
        for (k=i+1;k<n;k++)
            if (a[i][i]<a[k][i])
                for (j=0;j<=n;j++)
                {
                    double temp=a[i][j];
                    a[i][j]=a[k][j];
                    a[k][j]=temp;
                }

    for (i=0;i<n-1;i++)            //opakování eliminace
        for (k=i+1;k<n;k++)
            {
                double t=a[k][i]/a[i][i];
                for (j=0;j<=n;j++)
                    a[k][j]=a[k][j]-t*a[i][j];    //make the elements below the pivot elements equal to zero or elimnate the variables
            }
cout<<"\n\nMatice v trojuhelnikovem tvaru:\n";
    for (i=0;i<n;i++)            //nová matice
    {
        for (j=0;j<=n;j++)
            cout<<a[i][j]<<setw(16);
        cout<<"\n";
    }
    for (i=n-1;i>=0;i--)                //zpetna substituce
    {                        //x is an array whose values correspond to the values of x,y,z..
        x[i]=a[i][n];                //make the variable to be calculated equal to the rhs of the last equation
        for (j=0;j<n;j++)
            if (j!=i)            //then subtract all the lhs values except the coefficient of the variable whose value                                   is being calculated
                x[i]=x[i]-a[i][j]*x[j];
        x[i]=x[i]/a[i][i];            //now finally divide the rhs by the coefficient of the variable to be calculated
    }

    cout<<"\nHodnoty promenych:\n";
    for (i=0;i<n;i++)
        cout<<x[i]<<endl;            // Print the values of x, y,z,....
}
double det(int n, double **mat)
{
    int c, subi, i, j, subj;
    //double submat=**mat;
    double** submat=new double*[n]; // deklarace dynamickeho dvourozmerneho pole
    for (int i=0;i<n;++i)
        submat[i]=new double[n];

    if (n == 2)
    {
        return( (mat[0][0] * mat[1][1]) - (mat[1][0] * mat[0][1]));
    }
    else
    {
        for(c = 0; c < n; c++)
        {
            subi = 0;
            for(i = 1; i < n; i++)
            {
                subj = 0;
                for(j = 0; j < n; j++)
                {
                    if (j == c)
                    {
                        continue;
                    }
                    submat[subi][subj] = mat[i][j];
                    subj++;
                }
                subi++;
            }
        d = d + (pow(-1 ,c) * mat[0][c] * det(n - 1 ,submat));
        }
    }
    return d;
}
double **uziv_zapis(int n)
{
int j,i=0;
    cout.precision(1);        //nastaveni zaukrouhleni
    cout.setf(ios::fixed);
  /*  cout<<"\nMatice n-teho radu\n";
    cin>>n;*/               //matice n-teho radu
    double** a=new double*[n]; // deklarace dynamickeho dvourozmerneho pole
    for (int i=0;i<n;++i)
        a[i]=new double[n+1];
    //double x[n];        //declare an array to store the elements of augmented-matrix
    cout<<"\nVloz hodnoty matice:\n";
    for (i=0;i<n;i++)
        for (j=0;j<=n;j++)
            cin>>a[i][j];
            return a;
}

void vypis (double **a, int n)
{
    int i,j=0;
  cout<<"\nzvolena matice:\n";
    for (i=0;i<n;i++)            //výpis matice
    {
        for (j=0;j<=n;j++)
            cout<<a[i][j]<<setw(16);
        cout<<"\n";
    }
}

void del_array (double **a, int n)
{
for(int i = 0; i < n; ++i)
{
    {
    delete [] a[i];
    }
    delete [] a;

}
}
int main()
{
    int n;
    double **a;
    cout<< "Zadej matici n-teho radu"<<endl;
    cin >>n;
    a=uziv_zapis(n);
    vypis(a,n);
double x[n];
    gaus(a,x,n);
    cout<<endl<< det(n,a);
del_array(a,n);
    return 0;


string filename;

        ifstream file;
        cout << "Zadejte nazev souboru: ";
        cin >> filename;
        n = pocet_radku(filename);

        matice = file_load(filename, n);
        file.close();
}

 

 

Hostujeme u Českého hostingu       ISSN 1801-1586       ⇡ Nahoru Webtea.cz logo © 20032024 Programujte.com
Zasadilo a pěstuje Webtea.cz, šéfredaktor Lukáš Churý