에 대한 호출에 대해 일치하는 함수가 없습니다. C++에 매우 익숙하며 jacobi 메서드에 대해 지정된 반복 횟수를 수행하는 함수 "jacobi"를 호출하려고합니다 (또는 적어도 그렇게 할 수 있기를 바랍니다). 내가 'jacobi'라고 부르는 줄에서 "일치하는 함수가"jacobi "에 호출되지 않습니다. 다른 게시물을 읽었으며이 코드를 내 코드에 적용하려고했지만 실패했습니다. .이 문제를 일으키는 내 코드에 다른 문제가 언급 한 바와 같이 나는 아주 새로운 C++에서 그래서 어떤 도움을 주시면 감사하겠습니다 오전 나를 위해 그것을 무너 뜨리는하시기 바랍니다있다오류 :
#include <iostream>
using namespace std;
void jacobi (int size, int max, int B[size], int A[size][size], int init[size], int x[size]){
////
//// JACOBI
////
int i,j,k,sum[size];
k = 1;
while (k <= max) // Only continue to max number of iterations
{
for (i = 0; i < size; i++)
{
sum[i] = B[i];
for (j = 0; j < size; j++)
{
if (i != j)
{
sum[i] = sum[i] - A[i][j] * init[j]; // summation
}
}
}
for (i = 0; i < size; i++) ////HERE LIES THE DIFFERENCE BETWEEN Guass-Seidel and Jacobi
{
x[i] = sum[i]/A[i][i]; // divide summation by a[i][i]
init[i] = x[i]; //use new_x(k+1) as init_x(k) for next iteration
}
k++;
}
cout << "Jacobi Approximation to "<<k-1<<" iterations is: \n";
for(i=0;i<size;i++)
{
cout <<x[i]<< "\n"; // print found approximation.
}
cout << "\n";
return;
}
int main(){
// User INPUT
// n: number of equations and unknowns
int n;
cout << "Enter the number of equations: \n";
cin >> n;
// Nmax: max number of iterations
int Nmax;
cout << "Enter max number of interations: \n";
cin >> Nmax;
// int tol;
// cout << "Enter the tolerance level: " ;
// cin >> tol;
// b[n] and a[n][n]: array of coefficients of 'A' and array of int 'b'
int b[n];
int i,j;
cout << "Enter 'b' of Ax = b, separated by a space: \n";
for (i = 0; i < n; i++)
{
cin >> b[i];
}
// user enters coefficients and builds matrix
int a[n][n];
int init_x[n],new_x[n];
cout << "Enter matrix coefficients or 'A' of Ax = b, by row and separate by a space: \n";
for (i = 0; i < n; i++)
{
init_x[i] = 0;
new_x[i] = 0;
for (j = 0; j < n; j++)
{
cin >> a[i][j];
}
}
jacobi (n, Nmax, b, a, init_x, new_x);
}
매개 변수로 배열을 전달할 수 없으며 대부분 참조 또는 포인터를 전달할 수 있습니다. 매개 변수 인'int B [size]'문법은 불행한 거짓말이며, 사실상'int * B'만이 유효합니다. –
@UlrichEckhardt가 말한 것에 덧붙여,이 문제는 매개 변수'int A [size] [size] '에 있습니다. 그것은 "길이가'size' 인 int 배열이나 int (*) [size]'에 대한 포인터로 조정됩니다. 그런 다음 호환되지 않는 인수로 호출합니다. 또한 가변 길이 배열 (VLA)은 비표준 컴파일러 확장입니다. – juanchopanza
진술 : 프로그램의 모든 줄을 차례로 제거해보십시오. 대부분을 오류를 변경하지 않고 제거 할 수 있습니다 (예 : 'jakobi()'의 전신. 당신은 최소한의 예를 제시해야합니다. –