I found the mistake....
Posting it so that it would be helpful for others
Variable Q is not declared in LMIterm so Matlab doesnt consider it even though it is declared as variable.
So the equation "lmiterm([1 1 1 0],(A1*P+B1*Q)*P^(-1)*(A1*P+B1*Q).')" has to be split to multiple terms