%% Math 230, Spring 2011 %% Function for Problem 7 in Homework 10 function [C,s] = SqrDiff(A,B); % check if sizes of A and B are the same. If yes, proceed. if size(A)==size(B) C = A.^2 - B.^2; s = sum(sum(C)); else disp('Sizes of A and B not same. Quitting ...'); end %% OUTPUT FROM MATLAB >> m=4;n=5; >> A = round(10*rand(m,n)) A = 8 6 10 10 4 9 1 10 5 9 1 3 2 8 8 9 5 10 1 10 >> B = round(5*rand(m,n)) B = 3 3 3 1 3 0 4 1 0 2 4 4 4 0 5 5 2 0 4 0 >> [C,s] = SqrDiff(A,B) C = 55 27 91 99 7 81 -15 99 25 77 -15 -7 -12 64 39 56 21 100 -15 100 s = 877 >> m=3;n=7; >> A = round(5*rand(m,n)) A = 2 4 2 4 3 2 3 2 1 3 1 1 5 1 4 2 4 3 1 2 4 >> B = round(5*rand(m,n)) B = 1 4 1 4 1 1 2 3 5 1 1 5 1 2 3 3 1 4 2 3 4 >> [C,s] = SqrDiff(A,B) C = 3 0 3 0 8 3 5 -5 -24 8 0 -24 24 -3 7 -5 15 -7 -3 -5 0 s = 0