Reputation: 47
I am having difficulty creating a generic N x N identity matrix in Matlab.
I am given a system where
Ai,j =
{1, if i does not equal j
{n, if i = j}
You are asked to compute this when the value of the identity matrix n = 10, n = 20.
What I don't see is how to apply matrix indexing here. That is easy enough to do, but how do I account for the given linear system?
Upvotes: 3
Views: 281
Reputation: 563
There is a builtin function for creating a unit matrix called eye
.
have a look at the documentation http://au.mathworks.com/help/matlab/ref/eye.html?requestedDomain=au.mathworks.com
Also, ones(n,m)
creates a matrix of ones.
For a square matrix use (n-1)*eye(n) + ones(n)
and for non-square
(n-1)*eye(n, m) + ones(n, m)
Upvotes: 1