C Programming Thay are one problem Thank you Workout 1 Stead

C++ Programming:

Thay are one problem. Thank you

Workout 1) Steady State Temperature in a Thin Metal Plate Imagine a thin metal plate surrounded by heat sources along each edge, with the edges held at different temperatures, After a short time, the temperature at each location on the plate will settle into a steady state. This can be modeled by dividing the plate Into a discrete grid of cells and simulating the change In temperature of each cell over time 100 100 100100100 90 T3.) 3.2) T3.3 95 80 80 80 80 80 At each time step, the temperature in each interior cell (L) will be the average of four of its surrounding neighbors: a) Part 1 Develop a program to determntine the steady as a two-dimensional amay with NROWS rows and NCOLS columns, NROWS and NCOLS should be declared sate temperature disributon in the plate by representd as global constants (suggestion: use 20 for both values) Your program should do the following Declare 2 separate two-dimensional armeys named temp and oid. Amy old will be used maintain the current values of the grid temperatures and aay temp will be used to compute the new values obtained at each successive time step using the equation above Prompt the user and enter tempenture values for the top.botom. left. nighe sides. Also prompt a enter an initial temperature Tü) for the iaterior cells (For this lab, you may initialize all the interior cells to a single, user-input temperature) Amay old will be used to . Initialize temp using these values and display the initial contents of the temp array on the console Obtain a convergence criterion from the user (say, 0.001) Obtain a convergence criterion from the user (ay 0,001)

Solution

#include <iostream>
#include <cmath>

using namespace std;

const int NROWS= 10;
const int NCOLS= 10;

//display function
void display(double temp[][NCOLS]){
   int i, j;
   for(i=0; i<NROWS; i++){
       for(j=0; j<NCOLS; j++)
           std::cout<<temp[i][j]<<\" \";
       std::cout<<\"\ \";
   }
}

int main(){
   double temp[NROWS][NCOLS], old[NROWS][NCOLS];
   double temp_top, temp_right, temp_bottom, temp_left, temp_init;
   int i, j;
   double conv_criterion;
   bool steady;
   std::cout<<\"Enter temperature for top:\\t\";
   std::cin>>temp_top;
   std::cout<<\"Enter temperature for right:\\t\";
   std::cin>>temp_right;
   std::cout<<\"Enter temperature for bottom:\\t\";
   std::cin>>temp_bottom;
   std::cout<<\"Enter temperature for left:\\t\";
   std::cin>>temp_left;
   for(i=0; i<NCOLS; i++){
       temp[0][i]=temp_top;
       temp[NROWS-1][i]= temp_bottom;
   }
   for(i=1; i<NROWS-1; i++){
       temp[i][0]= temp_left;
       temp[i][NCOLS-1]= temp_right;
   }
   std::cout<<\"Enter initial temperature:\\t\";
   std::cin>>temp_init;
   for(i=1; i<NROWS-1; i++){
       for(j=1; j<NCOLS-1; j++)
           temp[i][j]= temp_init;
   }
   display(temp);
   std::cout<<\"Enter convergence criterion:\\t\";
   std::cin>>conv_criterion;
   //convergence loop
   do{
       steady = 1;
       for(i=0; i<NROWS; i++){
           for(j=0; j<NCOLS; j++)
               old[i][j]=temp[i][j];
       }
       for(i=1; i<NROWS-1; i++){
           for(j=1; j<NCOLS-1; j++)
               temp[i][j]=0.25*(old[i-1][j]+old[i+1][j]+old[i][j-1]+old[i][j+1]);
               if(std::abs(temp[i][j]-old[i][j])>conv_criterion)
                   steady= 0;
       }
   } while(steady== 0);
   display(temp);
   return 0;
}

C++ Programming: Thay are one problem. Thank you Workout 1) Steady State Temperature in a Thin Metal Plate Imagine a thin metal plate surrounded by heat sources
C++ Programming: Thay are one problem. Thank you Workout 1) Steady State Temperature in a Thin Metal Plate Imagine a thin metal plate surrounded by heat sources

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site