Modify the script so that if the matrices cannot be summed y
Solution
matlab code for the given problem
first of all initilaize the size of matrices and verify whether the dimension size of the all matrices are equal or not
if the dimensions of all the matrices are equal then go for the summation .... otherwise pront message as \" invalid entry please input four matrices of the same dismension and type \"
function [ Sum ] = my_matrixaddition( A,B,C,D )
A= input(\' enter the elements in to matrix A\');
B= input(\' enter the elements in to matrix B\');
C= input(\' enter the elements in to matrix C\');
D= input(\' enter the elements in to matrix D\');
[m,n]=size(A);
[k,l]=size(B);
[p q]=size(C)
[r s]=size(D)
sum=zeros(Sum);
sum=sum+A;
if((m==k)&&(n==l))
try
sum=sum+B;
else
catch
disp(\'invalid entry.please enter the same dimensions and same type values for the given matrices\');
end
end
if((m==p)&&(n==q))
try
sum=sum+C;
else
catch
disp(\'invalid entry.please enter the same dimensions and same type values for the given matrices\');
end
end
if((m==r)&&(n==s))
try
sum=sum+D;
else
catch
disp(\'invalid entry.please enter the same dimensions and same type values for the given matrices\');
end
end
disp(\'sum\');
end
