Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Edited to provide more information (sorry I don't know how to format matrices here)

I would like to replace: m = 4;

mult[i_, j_] := mult[i, j] = (tstar[Abs[i - j]] + tstar[i + j - 2])/2
Do[pmult[j] = Sum[a[i - 1]*mult[i, j], {i, 1, m}], {j, 1, m}]; 
Do[pmult[j] = Expand[pmult[j]], {j, 1, m}]; 
Do[c[j] = {}, {j, 1, m}]; 
Do[Do[c[j] = Append[c[j], Coefficient[pmult[j], tstar[i], 1]], {i, 0, 
    m - 1}], {j, 1, m}]; 
q = Transpose[Table[c[i], {i, 1, m}]]

with a single Table function (I believe this is possible). I attempted

mult[i_, j_] := mult[i, j] = (tstar[Abs[i - j]] + tstar[i + j - 2])/2
pmult[j_] := pmult[j] = Sum[a[i - 1]*mult[i, j], {i, 1, m}]; 
q = Table[
  Coefficient[Expand[pmult[j]], {j, 1, m}, tstar[i], 1], {j, 1, m}]

but I receive the error message

Coefficient::nonopt: Options expected (instead of 1) beyond position 3 in Coefficient[a(0) tstar(0)+a(1) tstar(1)+a(2) tstar(2)+a(3) tstar(3),1,tstar(i),1]. An option must be a rule or a list of rules. >>

The output should be

(a(0)   a(1)/2  a(2)/2  a(3)/2
a(1)    a(0)+a(2)/2 a(1)/2+a(3)/2   a(2)/2
a(2)    a(1)/2+a(3)/2   a(0)    a(1)/2
a(3)    a(2)/2  a(1)/2  a(0))

Can someone please shed some light on what I've done incorrectly? (i and j are indices) Thanks in advance!

share|improve this question
    
What is {j,1,m} in Coefficient[Expand[pmult[j]], {j, 1, m}, tstar[i], 1]? –  Peltio Feb 11 at 16:44
    
Sorry, m=4 (arbitrary), and j is an indices. –  gKirkland Feb 11 at 16:46
1  
Could you give a clean example of the input and output that you want? This will be easier than dissecting your Do loops and Appends etc. –  Mr.Wizard Feb 11 at 16:56
    
@Mr.Wizard The only input is the value m (mxm matrix is generated). I am having trouble dissecting it, also. This was written by someone else, and I am trying to write it in a simple, easier to understand, manner. The output will be an mxm matrix in terms of a[ ]'s. Sorry I don't know how to format outputs. –  gKirkland Feb 11 at 17:07
    
Okay, so q is the single output you are interested in, correct? –  Mr.Wizard Feb 11 at 17:10

1 Answer 1

up vote 2 down vote accepted

Please examine this and determine if it is giving the result that you desire:

m = 3;

mem : mult[i_, j_] := mem = (tstar[Abs[i - j]] + tstar[i + j - 2])/2

ptab = Table[Expand @ Sum[a[i - 1]*mult[i, j], {i, m}], {j, m}]

Table[Coefficient[j, tstar[i - 1], 1], {j, ptab}, {i, m}] // Transpose

If you include the definitions of a and tstar I may be able to simplify this further.

share|improve this answer
    
That's perfect! That cut my computation time by over half. I have rules to substitute in values for a and tstar later, so symbolic is how I need it at this point. Thanks so much! –  gKirkland Feb 11 at 17:29
    
@gKirkland Okay, I'm glad I could help, and thanks for the Accept. –  Mr.Wizard Feb 11 at 17:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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