• Status: Solved
• Priority: Medium
• Security: Public
• Views: 175

# this question is worth all my points. the one given yesterday and those left

here is what i have done so far. this is for this friday. please mail me with the answer as soon as you can.
after the program is the instructions of what i have to do. can you tell me of a good book about C programming.

/*Este programa calcula la temperatura de cada
punto interior de la plancha de metal e
imprime la tabla de los valores viejos y la
tabla de los valores nuevos.*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>

void main (void)
{
/* Declaracion de variables*/
float tvnorte, tvsur, tveste, tvoeste;
float tv[10][15], tn[10][15], error;
int i, j;

/*Leer valores constantes de un file*/
FILE*viejo;
FILE*nuevo;
nuevo=fopen("pedro.out","w");
viejo=fopen("aixa.dat","r");

fscanf(viejo, "%f",&tvnorte);
fscanf(viejo, "%f",&tvsur);
fscanf(viejo, "%f",&tveste);
fscanf(viejo, "%f",&tvoeste);

tv[0][0]  = (tvnorte + tvoeste)/2.0;
tv[0][14] = (tvnorte + tveste)/2.0;
tv[9][0]  = (tvsur + tvoeste)/2.0;
tv[9][14] = (tvsur + tveste)/2.0;

tn[0][0] = tv[0][0];
tn[0][14] = tv[0][14];
tn[9][0] = tv[9][0];
tn[9][14] = tv[9][14];

for(j=1;j<=13; j++)
{
i=0;
tv[i][j] = 100.0;
tn[i][j] = tv[i][j];
}
for (i=1; i<=8; i++)
{j=0;
tv[i][j] = 0.0;
tn[i][j] = tv[i][j];
}
for(j=1;j<=13; j++)
{i=9;
tv[i][j] = 50.0;
tn[i][j] = tv[i][j];
}
for(i=1;i<=8; i++)
{j=14;
tv[i][j] = 75.0;
tn[i][j] = tv[i][j];
}
for(i=1;i<=8;i++)
{
for(j=1;j<=13;j++)
{
tv[i][j] = 24.0;
}
}
fprintf(nuevo,"tabla temperatura vieja:\n");
for(i=0;i<=9;i++)
{
for(j=0;j<=14;j++)
{fprintf(nuevo,"%4.0f", tv[i][j]);}
fprintf(nuevo,"\n");
}
fprintf(nuevo,"\n");

/*tv ends here*/

while(error<=0.000001)
{
error =fabs(tv[i][j] - tn[i][j]);

for(i=1;i<=8;i++)
{

for(j=1;j<=13;j++)
{
tn[i][j] = (tv[i-1][j]+tv[i][j-1]+tv[i][j+1]+tv[i+1][j])/4.0;

}

}

}

fprintf(nuevo,"tabla temperatura nueva:\n");
for(i=0;i<=9;i++)
{
for(j=0;j<=14;j++)
{
fprintf(nuevo,"%4.0f", tn[i][j]);
}
fprintf(nuevo,"\n");
}

fclose(nuevo);
fclose(viejo);
}

Suppose that the edges of a thin square metal &e maintained at different temperatures: 100 C (north edge), 75 C (east edge), 50 C (south edge) and 0 (east edge) and we whish to determine the steady state temperature at each interior point. To do this we divide the plate into 10 rows and 15 colurnns.

Each corner of the small squares is called a node. The new temperature (tn) in the interior nodes can be calculate form the old ones (to) by:

tn[i][j] = (tv[i-1][j]+tv[i][j-1]+tv[i][j+1]+tv[i+1][j])/4.0

Write a program that calculate each interior point at steady state. The program must accomplish the following:
(1)      Initialize the temperature of all nodes (named it the old temperature '~o") as follows:
Read from a file the four constant temperatures along each edge and initialize the temperature of the nodes located along each edge. (these temperatures are constant.
Calculate each comer as the arithmetic average of the adjacent edges.
initialize the interior nodes with a guess temperature.

(2)      Print the old temperature array in a file of results.

(2)      Calculate the new temperature (tn) of the interior nodes by repeatedly averaging the temperatures at its four neighbors with the formula above. Repeat this procedure until the new temperature at each interior node differs from the old temperature by no more than 1 .0e-6.

(3)      Print the new temperature array and the number of iterations used to produce the fmal result in the same results file.
0
pedro10
1 Solution

Author Commented:
help!!!!!!!!!!!!!!!
0

Commented:
You should delete this question and provide the information that has been asked for on the already existing question. What is going wrong with the program? What error message are you getting? When? During compilation? or Execution? etc. etc.

0

Commented:
That loop structure looks definitely wrong. I'm hazarding a guess
at what you're trying to do is to reiterate your structure again
and again until there's no change. If that is the case, I'm afraid that loop is definitely not doing it. It's only examining the change at one node.

You're also wrong in using a pre-tested loop, you should
be using a post-tested loop. Try: (pseudo-code)

do
{
error = 0;
for (i=..
for (j=..
{
tn1[i][j] =(tn[i-1][j]+tn[i][j-1]+tn[i][j+1]+tn[i+1][j])/4.0;
error += fabs(tn1[i][j] - tn[i][j]);
}
for (i=..
for (j=..
{
tn[i][j]=tn1[i][j];
}
}
while (error>0);

i.e. make a new variable tn1 to be your new iteration. Calculate
tn1-tn which should be your difference, renew tn and check to
see if tn has changed. This doesn't take into account the
risk of oscillation! ;-)
0

Commented:
I have modified the code for this that provides the following answers

tabla temperatura vieja:
75 100 100 100 100 100 100 100 100 100 100 100 100 100  50
50  56  56  56  56  56  56  56  56  56  56  56  56  56   0
50  56  56  56  56  56  56  56  56  56  56  56  56  56   0
50  56  56  56  56  56  56  56  56  56  56  56  56  56   0
50  56  56  56  56  56  56  56  56  56  56  56  56  56   0
50  56  56  56  56  56  56  56  56  56  56  56  56  56   0
50  56  56  56  56  56  56  56  56  56  56  56  56  56   0
50  56  56  56  56  56  56  56  56  56  56  56  56  56   0
50  56  56  56  56  56  56  56  56  56  56  56  56  56   0
63  75  75  75  75  75  75  75  75  75  75  75  75  75  38

tabla temperatura nueva:
75 100 100 100 100 100 100 100 100 100 100 100 100 100  50
50  75  85  89  91  92  93  92  91  89  86  81  71  51   0
50  65  75  81  84  86  86  85  83  80  75  66  53  32   0
50  61  69  75  78  80  80  80  77  73  66  56  42  24   0
50  58  65  71  74  76  76  75  72  68  61  51  37  20   0
50  57  64  68  72  73  74  73  70  65  58  49  35  19   0
50  57  63  68  71  72  72  71  69  65  59  50  37  20   0
50  59  65  69  71  72  72  72  70  67  62  54  43  26   0
50  63  69  71  73  73  73  73  72  70  68  63  55  39   0
63  75  75  75  75  75  75  75  75  75  75  75  75  75  38

Do you want it?

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

## Featured Post

Tackle projects and never again get stuck behind a technical roadblock.