I have two functions as shown below:
1.
void calcoeff (double gamma, double delx, double A, double B, int n)
{
int i;
double halfdelx, sp = 0;
double diag[n], upp[n-1], low[n-1], righ[n], X[n], sc[n];
halfdelx = delx / 2;
for (i = 1; i <= n; i++)
{
X[i] = i - 0.5;
sc[i] = 8 * X[i];
if (i == 1 || i == n)
{
diag[i] = ((gamma/delx) + (gamma/halfdelx) + sp);
}
else
diag[i] = ((gamma/delx) + (gamma/delx) + sp);
cout << "\ndiag" << i << "=" << diag[i] << "\n";
}
for (i = 1; i <= n-1; i++)
{
upp[i] = -1 * (gamma/delx);
low[i] = -1 * (gamma/delx);
cout << "\nupp" << i << "=" << upp[i] << setw(15) << "low" << i << "=" << low[i] << "\n";
}
for (i = 1; i <= n; i++)
{
if (i == 1){righ[i] = ((1/halfdelx) * A + sc[i]);}
else if (i == n)
{
righ[i] = ((1/halfdelx) * B + sc[i]);
}
else
righ[i] = sc[i];
cout << "\nrigh" << i << "=" << righ[i] << "\n";
}
return;
}
2.
void TDMA (double diag[], double upp[], double low[], double righ[], int n)
{
int i;
double fact, phi[n];
for (i = 2; i <= n; i++)
{
fact = low[i-1] / diag[i-1];
diag[i] = diag[i] - fact * upp[i-1];
righ[i] = righ[i] - fact * righ[i-1];
}
phi[n] = righ[n] / diag[n];
for (i = n-1; i >= 1; i--)
{
phi[i] = (righ[i] - (upp[i] * phi[i+1])) / diag[i];
}
cout << "\nThe solution is as follows:\n";
for (i = 1; i <= n; i++)
{
cout << "\nphi" << i << " = " << phi[i] << endl;
}
return;
}
The first function calculates and gives four arrays which has to be sent to second function as input parameters to get final phi array. So in the main function I have declared all the variables required by these two functions and I have called these two functions successively in the same order. The problem which I have noticed is that the first function is giving four arrays with correct values but the second function is not giving the correct result (as per the code). I have also noticed that the arrays given by first function are not going into second function as input parameters. The second function calculation is all based on the arrays given by first function. Can anyone help me in how to send the output of first function to second function? Thanks in advance.