1
$\begingroup$

bear with me as I'm very inexperienced with Mathematica, although I think my problem is reasonably straight forward:

I'm currently trying to find a matrix from a simple expression. I've found a way to extract the matrix, however there still remains a constraint that I must somehow impose in order for the matrix to be correct. Here is what I have:

nn = 10;
row[n_] := Sum[(p + 1 + R + 3 n^2) a[p], {p, 0, nn - 1}] + \[Alpha] a[n - 1]
vector = Table[a[i], {i, 0, nn - 1}];
matrix = Table[D[row[i], vector[[j]]], {i, 1, nn}, {j, 1, nn}]

This produces a matrix which is fantastic. However, I still have two "boundary conditions" left to impose which are (written in Mathematica code):

Sum[a[n],{n,0,nn-1}]=0
Sum[n^2a[n],{n,0,nn-1}]=0

Does anyone have any ideas of how I can impose these constraints upon the above set of code, such that the end matrix takes them into account?

Thank you :)

Edit:

nn = 10;
row[n_] := Sum[(p + 1 + R + 3 n^2) a[p], {p, 0, nn - 1}] + \[Alpha] a[n - 1]
vector = Table[a[i], {i, 0, nn - 1}];
matrix = Table[D[row[i], vector[[j]]], {i, 1, nn}, {j, 1, nn}]
matrix /. { a[0] -> -Sum[i^2 a[i],{i,2,nn-1}] - Sum[a[i],{i,1,nn-1}], a[1] -> -Sum[i^2 a[i],{i,2,nn-1}]}
$\endgroup$

1 Answer 1

1
$\begingroup$

You may use the 2 equations to eliminate 2 of the a[n]. E.g. to eliminate a[0]and a[1]:

From Sum[a[n],{n,0,nn-1}]=0 and Sum[n^2a[n],{n,0,nn-1}]=0 we get:

a[0]== -Sum[a[i],{i,1,nn-1}]
a[1]== -Sum[i^2 a[i],{i,2,nn-1}]

Or:

a[0]==  -Sum[i^2 a[i],{i,2,nn-1}] - Sum[a[i],{i,1,nn-1}]
a[1]== -Sum[i^2 a[i],{i,2,nn-1}]

To insert this into matrix, you can use ReplaceAll (/.) and a Rule (.. -> ..), look this up in the manual:

matrix /. {
  a[0] -> -Sum[i^2 a[i],{i,2,nn-1}] - Sum[a[i],{i,1,nn-1}],
  a[1] -> -Sum[i^2 a[i],{i,2,nn-1}]}
$\endgroup$
3
  • $\begingroup$ Thank you very much for your answer. I see, so I can impose these conditions upon the matrix simply by rearranging the constraining sums. How would I go about inserting this into the code? $\endgroup$
    – James
    Mar 23, 2021 at 11:02
  • $\begingroup$ I added this to my answer. $\endgroup$ Mar 23, 2021 at 11:07
  • $\begingroup$ Ah yes, amazing stuff! I've added an edit to my original post which is what I think my code should now look like. Does it look okay? Thank you again for you time, it is greatly appreciated. $\endgroup$
    – James
    Mar 23, 2021 at 11:26

Your Answer

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

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