hello
the first diag in your statement just generates a constant 1
which means, it just plus 1 to the sum(diag(1,-1), diag(1,1))
you may see it from the following:
diag(1)
ans =
1
?diag(1,-1)
ans =
0 0
1 0
?diag(1,1)
ans =
0 1
0 0
so you have to specify the all the diagnal elements in you matrix
just like this
diag([1,1])
or
diag([1,0])
then it will be OK.
hello
the first diag in your statement just generates a constant 1
which means, it just plus 1 to the sum(diag(1,-1), diag(1,1))
you may see it from the following:
diag(1)
ans =
1
?diag(1,-1)
ans =
0 0
1 0
?diag(1,1)
ans =
0 1
0 0
so you have to specify the all the diagnal elements in you matrix
just like this
diag([1,1])
or
diag([1,0])
then it will be OK.