I can't make matrices with variables in it for some reason. I get following message.
>>> A= [a b ;(-1-a) (1-b); (1+a) b]
error: horizontal dimensions mismatch (2x3 vs 1x1)
Why is it? Please show me correct way if I'm wrong.
I can't make matrices with variables in it for some reason. I get following message.
>>> A= [a b ;(-1-a) (1-b); (1+a) b]
error: horizontal dimensions mismatch (2x3 vs 1x1)
Why is it? Please show me correct way if I'm wrong.
In Matlab you first need to assign a variable before you can use it,
This will thus give an error,
Matlab does never accept unassigned variables. This is because, on the lowest level, you do not have
a
. You will have machine code which is assgined the value ofa
. This is handled by the JIT compiler in Matlab, so you do not need to worry about this though.If you want to use something as the variable which you have in maths you can specifically express this to matlab. The object is called a
sym
and the syntax that define thesym
x to a variablex
is,That said, you can define a vector or a matrix as,
The size of a matrix can be found with
size(M)
or for dim nsize(M,n)
. You can calcuate the matrix product M3=M1*M2 if and only if M1 have the size m * n and M2 have the size n * p. The size of M3 will then be m * p. This will also mean that the operation A^N = A * A * ... is only allowed when m=n so to say, the matrix is square. This can be verified in matlab by the comparison,These are the basic rules for assigning variables in Matlab as well as for matrix multiplication. Further, a google search on the error error: 'x' undefined does only give me octave hits. Are you using octave? In that case I cannot guarantee that you can use
sym
objects or that the syntaxes are correct.