hw9problem2

hw9problem2 - elseif r==1 % Location is along top edge of...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
%Homework 9 Problem 2 % This recalculates the temperature of an element based % upon the temperatures of the surrounding elements. % INPUT ARGUMENTS: temp_matrix, the matrix of the temperature values for the cover plate % r, the row component of the element being recalculated % c, the column component of the element being recalculated % OUTPUT ARGUMENTS: new_temp -The updated temperature for the element of interest % %Input Section temp_matrix = load('temperature1.txt'); r = 1; c = 2; [n,m] = size(temp_matrix) %Determination of the size of the matrix %Calculation Section if r==1 && c==1 % Location is top left corner new_temp = (temp_matrix(r+1,c) + temp_matrix(r,c+1))/2; elseif r==1 && c==m % Location is top right corner new_temp = (temp_matrix(r+1,c) + temp_matrix(r,c-1))/2; elseif r==n && c==1 % Location is bottom left corner new_temp = (temp_matrix(r-1,c) + temp_matrix(r,c+1))/2; elseif r==n && c==m % Location is bottom right corner new_temp = (temp_matrix(r-1,c) + temp_matrix(r,c-1))/2;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: elseif r==1 % Location is along top edge of the matrix new_temp = (temp_matrix(r+1,c) + temp_matrix(r+1,c) + temp_matrix(r,c-1) + temp_matrix(r,c+1))/4; elseif r==n % Location is along bottom edge of the matrix new_temp = (temp_matrix(r-1,c) + temp_matrix(r-1,c) + temp_matrix(r,c-1) + temp_matrix(r,c+1))/4; elseif c==1 % Location is along left edge of the matrix new_temp = (temp_matrix(r-1,c) + temp_matrix(r+1,c) + temp_matrix(r,c+1) + temp_matrix(r,c+1))/4; elseif c==1 % Location is along right edge of the matrix new_temp = (temp_matrix(r-1,c) + temp_matrix(r+1,c) + temp_matrix(r,c-1) + temp_matrix(r,c-1))/4; else % Location is in the middle of matrix new_temp = (temp_matrix(r-1,c) + temp_matrix(r+1,c) + temp_matrix(r,c-1) + temp_matrix(r,c+1))/4; end % ---- Output Section ----fprintf('The original temperature of %5.2f has been updated to %5.2f \n',temp_matrix(r,c),new_temp)...
View Full Document

Ask a homework question - tutors are online