To create a matrix in Matlab, the elements should be wrapped in square brackets []
. To create a 2x2 identity matrix, we can use the built-in function eye()
as follows:
main.m13 chars2 lines
gives
main.m32 chars5 lines
To multiply a
with b
, we use the *
operator. Hence, the code would look like this:
main.m43 chars4 lines
gives
main.m31 chars5 lines
Alternatively, we can use the mtimes()
function to get the same result:
main.m17 chars2 lines
which also gives the same result:
main.m31 chars5 lines
gistlibby LogSnag