Hi,
I am new to matlab and i have been given a question i have no idea how to do. here it is
"Write a matlab script that uses a “if” statement to check if the inner dimensions of two matrices A
and B are the same. This program should be useable for matrices of any size so you should use the
“size” command.
Question 2
If the inner dimensions the same then you must.
(i) use nested “for” loops to determine a matrix C from the matrix product of A and B (Note: Here
you need to use the “for” loops to sum the products of the elements of A and B, i.e.
(this equation won't show on boards but it's here at this link
http://www.mathworks.co.uk/help/matlab/ref/mtimes.html )
Where cij
is the (i,j) element of matrix C, etc..
(ii) Check if the value of each element of your computed C matrix is the same as the value calculated
using the standard Matlab matrix multiplication (D=A*B).
(iii) For any elements of C that are not equal to the corresponding elements of D, you need to write a
warning statement to the command window stating that the value is incorrect for that particular
element of matrix C. It should read something like:
“Warning: Column 3 row 4 of Matrix C is incorrect. It has a computed value of 24. Its value should be
26”"
and so far i have done
"clear all
a=[1 2 3; 4 5 6; 7 8 9]
b=[2 4; 5 6; 7 8]
c=a*b
i= size(a)
j= size(b)
k=3
y=2
for n=1:y
i=1:k
for ;
c(n,i)=0;
for j=1:k
c(n,i)=c(n,i)+ a(i,j)*b(j,n)
end
end
end
could someone who's very used to matlab please tell me where I'm going wrong or show me how to do the problem
thanks