A square plate divided in 100 squares or nodes by a grid. the temperature of the nodes form a two-dimensional array T[j] .the temperature in all nodes at the edge of the plate is constrained to be 20*C by a cooling system, and the temperature and the temperature of the node[3][8] is fixed at 100*C by exposure to boiling water, i.e., T[3][8]=100. A new estimate of the temperature T[j] in any given node can be calculated from the average of the temperatures in all segments surrounding it; T[j]=(T[i+1][j] + T[j+1] + T[j-1])/4.0
initial temperature assumption in each node is 20*C. find the steady-temperature at[5][5].

The thing that is giving me trouble is how to structure my array. I don't understand how to set up the array when I am trying to find the values within the array itself.

The thing that is giving me trouble is how to structure my array. I don't understand how to set up the array when I am trying to find the values within the array itself.

You put values into the array and look through the array to find values.

Is this a class for computer science, numerical analysis or math.phys.?

In any case, the way the assignment is written, you'll need 2 10x10 arrays. Iterate over the "first" storing new estimates in the "second". Compare the "second" values to the "first" using a proper metrics to find out if there's no progress anymore, and it's time to stop iterations. If another iteration is still necessary, copy the "second" values into the "first" and keep going. That's a CS approach.

Alternatively (MP approach), forget the initial conditions. Realize that what you have is a Laplace system of 63 equations with 63 unknowns. Just solve it.

PS:

average of the temperatures in all segments surrounding it; T[j]=(T[i+1][j] + T[j+1] + T[j-1])/4.0

There's surely a typo here. What happened to T[i-1][j]?

Edited 6 Years Ago by nezachem: n/a

    int i=1,j=1;
    double temp=[10][10];
    diff_of_array(T,temp);

    double T[10][10]= {{20,20,20,20,20,20,20,20,20,20},{20,20,20,20,20,20,20,20,20,20},
    {20,20,20,20,20,20,20,100,20,20},{20,20,20,20,20,20,20,20,20,20},{20,20,20,20,20,20,20,20,20,20},
    {20,20,20,20,20,20,20,20,20,20},{20,20,20,20,20,20,20,20,20,20},{20,20,20,20,20,20,20,20,20,20},
    {20,20,20,20,20,20,20,20,20,20},{20,20,20,20,20,20,20,20,20,20}};


    for(i=1;i++;i<=10)
    {
        for(j=1;j++;j<=10)
        {
            T[i][j]= (T[i+1][j]+T[i-1][j]+T[i][j+1]+T[i][j-1])/4.0;

            if(i==5&&j==8)
            {
                T[i][j]=100;
            }

            temp[i][j]= T[i][j];
        }
    }

}

void diff_of_array(double& T,double& temp)
{
    int i=1,j=1;
    double T_2=[10][10];
    double T_diff=0;

    for(i=1;i++;i<=10)
    {
        for(j=1;j++;j<=10)
        {
            T_2[i][j]=abs({temp[i][j]-T[i][j]});
        }
            T_diff=T_diff + T_2[i][j];
    }

}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

First of all, use code tags.
Second, it's not what I advised you.

for(i=1;i++;i<=10) {
    for(j=1;j++;j<=10) {
        T[i][j]= (T[i+1][j]+T[i-1][j]+T[i][j+1]+T[i][j-1])/4.0;
        if(i==5&&j==8){
            T[i][j]=100;
        }
        temp[i][j]= T[i][j];
    }
}

is surely wrong. The whole point was to calculate temp based on T:

for(i=1;i++;i<=10) {
    for(j=1;j++;j<=10) {
        temp[i][j]= (T[i+1][j]+T[i-1][j]+T[i][j+1]+T[i][j-1])/4.0;
    }
temp[3][8] = 100;
}

and then copy temp back to T.
Now, about loop conditions: i <= 10 is also wrong. Can you figure out why (hint: in C, indexing starts with 0, yet in this case i = 1 is surprisingly correct), and how to do it right?

PS: I intentionally omit one important step.

This article has been dead for over six months. Start a new discussion instead.