Matlab: ask the user to enter the dimension of square matrices he/she wants to e
ID: 669945 • Letter: M
Question
Matlab: ask the user to enter the dimension of square matrices he/she wants to enter (let’s call it N). Then enter two matrices (let’s call them A and B), each of dimensions N by N (suggestion – don’t make N too big). Then, in your program, please calculate a new matrix (let’s call it C), which will be the sum of the two matrices you entered (i.e. C=A+B). Display the result matrix (matrix C) by just calling it in the program (i.e. by just typing C, without the semicolon behind it).
i have this but dont think its right
N = input('Enter dimension of square matrix: ');
A = magic(N);
B = magic(N);
C = A+B
Explanation / Answer
A=magic(n);
B=magic(n);
n=input('please enter a value for n:')
for i=1:n
for j=1:n
c(i,j)=A(i,:)+B(:,j);
end
end