# Backward Finite Difference Heat Equation error

• Feldman Sia
In summary, the conversation discusses an error in the code for a heat equation backward-difference algorithm. The error is listed as "missing type specifier - int assumed" and "ambiguous call to overloaded function". The conversation also mentions a discussion on how to handle the output of the code and suggests possible solutions to fix the error, such as passing a float instead of an integer or hard coding a numeric value for pi.
Feldman Sia
I had these code in this forum but comes out error as below, any suggestion?

Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\username\documents\visual studio 2010\projects\fdm 001\fdm 001\explicit 001.cpp 27
Error 2 error C2668: 'atan' : ambiguous call to overloaded function c:\users\username\documents\visual studio 2010\projects\fdm 001\fdm 001\explicit 001.cpp 82
3 IntelliSense: more than one instance of overloaded function "atan" matches the argument list: c:\users\username\documents\visual studio 2010\projects\fdm 001\fdm 001\explicit 001.cpp 82

/*
* HEAT EQUATION BACKWARD-DIFFERENCE ALGORITHM 12.2
*
* To approximate the solution to the parabolic partial-differential
* equation subject to the boundary conditions
* u(0,t) = u(l,t) = 0, 0 < t < T = max t,
* and the initial conditions
* u(x,0) = F(x), 0 <= x <= l:
*
* INPUT: endpoint l; maximum time T; constant ALPHA; integers m, N.
*
* OUTPUT: approximations W(I,J) to u(x(I),t(J)) for each
* I = 1, ..., m-1 and J = 1, ..., N.
*/

#include <stdio.h>
#include <math.h>
#define pi 4*atan(1)
#define true 1
#define false 0

double F(double X);
void INPUT(int *, double *, double *, double *, int *, int *);
void OUTPUT(double, double, int, double *, double);

main()
{
double W[25], L[25], U[25], Z[25];
double FT,FX,ALPHA,H,K,VV,T,X;
int N,M,M1,M2,N1,FLAG,I1,I,J,OK;

INPUT(&OK, &FX, &FT, &ALPHA, &N, &M);
if (OK) {
M1 = M - 1;
M2 = M - 2;
N1 = N - 1;
/* STEP 1 */
H = FX / M;
K = FT / N;
VV = ALPHA * ALPHA * K / ( H * H );
/* STEP 2 */
for (I=1; I<=M1; I++) W[I-1] = F( I * H );
/* STEP 3 */
/* STEPS 3 through 11 solve a tridiagonal linear system
using Algorithm 6.7 */
L[0] = 1.0 + 2.0 * VV;
U[0] = -VV / L[0];
/* STEP 4 */
for (I=2; I<=M2; I++) {
L[I-1] = 1.0 + 2.0 * VV + VV * U[I-2];
U[I-1] = -VV / L[I-1]; }
/* STEP 5 */
L[M1-1] = 1.0 + 2.0 * VV + VV * U[M2-1];
/* STEP 6 */
for (J=1; J<=N; J++) {
/* STEP 7 */
/* current t(j) */
T = J * K;
Z[0] = W[0] / L[0];
/* STEP 8 */
for (I=2; I<=M1; I++)
Z[I-1] = ( W[I-1] + VV * Z[I-2] ) / L[I-1];
/* STEP 9 */
W[M1-1] = Z[M1-1];
/* STEP 10 */
for (I1=1; I1<=M2; I1++) {
I = M2 - I1 + 1;
W[I-1] = Z[I-1] - U[I-1] * W;
}
}
/* STEP 11 */
OUTPUT(FT, X, M1, W, H);
}
/* STEP 12 */
return 0;
}
/* Change F for a new problem */
double F(double X)
{
double f;

f = sin(pi * X);
return f;
}

void INPUT(int *OK, double *FX, double *FT, double *ALPHA, int *N, int *M)
{
int FLAG;
char AA;

printf("This is the Backward-Difference Method for Heat Equation.\n");
printf("Has the function F been created immediately\n");
printf("preceding the INPUT procedure? Answer Y or N.\n");
scanf("\n%c", &AA);
if ((AA == 'Y') || (AA == 'y')) {
printf("The lefthand endpoint on the X-axis is 0.\n");
*OK =false;
while (!(*OK)) {
printf("Input the righthand endpoint on the X-axis.\n");
scanf("%lf", FX);
if (*FX <= 0.0)
printf("Must be positive number.\n");
else *OK = true;
}
*OK = false;
while (!(*OK)) {
printf("Input the maximum value of the time variable T.\n");
scanf("%lf", FT);
if (*FT <= 0.0)
printf("Must be positive number.\n");
else *OK = true;
}
printf("Input the constant alpha.\n");
scanf("%lf", ALPHA);
*OK = false;
while (!(*OK)) {
printf("Input integer m = number of intervals on X-axis\n");
printf("and N = number of time intervals - separated by a blank.\n");
printf("Note that m must be 3 or larger.\n");
scanf("%d %d", M, N);
if ((*M <= 2) || (*N <= 0))
printf("Numbers are not within correct range.\n");
else *OK = true;
}
}
else {
printf("The program will end so that the function F can be created.\n");
*OK = false;
}
}

void OUTPUT(double FT, double X, int M1, double *W, double H)
{
int I, J, FLAG;
char NAME[30];
FILE *OUP;

printf("Choice of output method:\n");
printf("1. Output to screen\n");
printf("2. Output to text file\n");
scanf("%d", &FLAG);
if (FLAG == 2) {
printf("Input the file name in the form - drive:name.ext\n");
printf("for example: A:OUTPUT.DTA\n");
scanf("%s", NAME);
OUP = fopen(NAME, "w"); }
else OUP = stdout;
fprintf(OUP, "THIS IS THE BACKWARD-DIFFERENCE METHOD\n\n");
fprintf(OUP, " I X(I) W(X(I),%12.6e)\n", FT);
for (I=1; I<=M1; I++) {
X = I * H;
fprintf(OUP, "%3d %11.8f %14.8f\n", I, X, W[I-1]);
}
fclose(OUP);
}

a couple of ideas...1) I would stop passing an integer to the function atan, namely, a 1 without a decimal point, and start passing a float, namely, 1.0 ...or...2) I would stop using the function atan altogether and simply hard code a numeric value for pi with a reasonable number of decimals.

After all, check values of your matrix. May your algorithm works only with diagonal dominant matrix.

## 1. What is the Backward Finite Difference Heat Equation?

The Backward Finite Difference Heat Equation is a mathematical equation used to model the flow of heat in a system over time. It is a partial differential equation that takes into account the temperature distribution, thermal conductivity, and heat generation of a system.

## 2. How is the Backward Finite Difference Heat Equation solved?

The Backward Finite Difference Heat Equation is typically solved using numerical methods such as the finite difference method. This involves dividing the system into a grid and approximating the derivatives in the equation using the values at each grid point. The equation is then solved iteratively until a stable solution is reached.

## 3. What is Backward Finite Difference Heat Equation error?

Backward Finite Difference Heat Equation error refers to the difference between the exact solution of the Backward Finite Difference Heat Equation and the numerical solution obtained through the finite difference method. It is a measure of the accuracy of the numerical solution and is affected by factors such as grid size and time step.

## 4. How can Backward Finite Difference Heat Equation error be minimized?

To minimize Backward Finite Difference Heat Equation error, one can decrease the grid size and time step used in the finite difference method. This will result in a more accurate approximation of the derivatives in the equation. Additionally, using higher order finite difference methods can also reduce error.

## 5. What are the applications of the Backward Finite Difference Heat Equation?

The Backward Finite Difference Heat Equation has various applications in fields such as physics, engineering, and mathematics. It is commonly used to model heat transfer in materials, such as in the design of heating and cooling systems. It can also be used to study diffusion processes and other phenomena involving heat transfer.

• MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
6K
• Programming and Computer Science
Replies
3
Views
1K
• Programming and Computer Science
Replies
1
Views
2K
• Engineering and Comp Sci Homework Help
Replies
19
Views
2K
• Engineering and Comp Sci Homework Help
Replies
3
Views
1K
• MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
• Programming and Computer Science
Replies
2
Views
1K
• Engineering and Comp Sci Homework Help
Replies
2
Views
1K
• Introductory Physics Homework Help
Replies
11
Views
912
• Programming and Computer Science
Replies
1
Views
1K