hw9problem2

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

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

%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;
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

## This note was uploaded on 02/12/2012 for the course ENGR 126 taught by Professor Oakes during the Fall '08 term at Purdue.

Ask a homework question - tutors are online