0
$\begingroup$

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

a[0] = {{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[5] /. m [[1]] // MatrixForm

Part::partw: Part 1 of {} does not exist. >>
$\endgroup$
1
  • $\begingroup$ 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! $\endgroup$
    – Michael E2
    Commented Sep 27, 2016 at 14:59

1 Answer 1

1
$\begingroup$

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[0] but the loop goes through a[1], a[2] etc.

n = 5;

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

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

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[[1]] // MatrixForm

enter image description here

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).

$\endgroup$
1
  • $\begingroup$ Dear corey979 Thanks alot $\endgroup$
    – mary
    Commented Sep 27, 2016 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.