I want to solve some Lyapunov equations for stability analysis and find the solution of Ricatti equations based on Matrices. How can I do this in Matlab?
In order to solve Lyapunov or general linear matrix inequalities you need the LMI matlab toolbox. You can find other free software for LMI solution on the web, just look for lmi solvers on your internet search interface.
Lyapunov equation is a linear equation. Just write it in A x = b form and solve it. Riccati equation is a nonlinear equation, you can use policy iteration method to solve it. See the book by Prof. Lemon Zhou, Prof. Doyle, and Prof. Glover for it.