# Do Loop with Solve not working

I am trying to solve bellowing loop but I faced with following error!

a = {{0, 1},{2, 3}};
c = {{1, 2},{1, 4}};
p[k] = {{p1[k], p2[k]},{p3[k], p4[k]}};
Do[
m = Solve[
Transpose[a[k]].p[k] + p[k].a[k] + c == 0,
{p1[k], p2[k], p3[k], p4[k]}],
{k, 0, 5}
];
p /. m [] // MatrixForm

Part::partw: Part 1 of {} does not exist. >>

• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Sep 27 '16 at 14:59

You are solving a system of equations organized in a matrix, hence you have to Equal (==) each of the four equations - MMA doesn't know that your 0 is a $2\times 2$ zero matrix. Next, you only provide a but the loop goes through a, a etc.

n = 5;

c = {{1, 2}, {1, 4}};

a = {{0, 1}, {2, 3}};
a[i_] := a[i - 1] + IdentityMatrix;

p[k_] := {{p1[k], p2[k]}, {p3[k], p4[k]}};
Do[
m = Solve[
Transpose[a[k]].p[k] + p[k].a[k] + c == {{0, 0}, {0, 0}}, {p1[k],
p2[k], p3[k], p4[k]}]
, {k, 0, n}];

p[n] /. m[] // MatrixForm I set an arbitrary a[i] through recursion for illustration, changed p[k] to an explicit function and gave n = 5 as the max iterator of the loop (works for arbitrary n, e.g. n = 500).

• Dear corey979 Thanks alot – mary Sep 27 '16 at 15:56