New Reply

Mathematica: Need help to modify the code

 
Share Thread
Jun6-12, 09:48 AM   #1
 

Mathematica: Need help to modify the code


Hi all,
I need help to edit the code so that the arrangment of the outputs match the one that Iam looking for.

For instance:
term[n_Integer, m_Integer] :=
Apply[Dot, Table[matg[[i]], {i, m + 1, n}]].hl[[m]] /; (n >= m);
Subscript[lay, s_] := Sum[term[s, i], {i, s}];

In[1]: Subscript[lay,3]
Out[1]: matg[[3]].hl[[2]] + matg[[2]].matg[[3]].hl[[1]] + hl[[3]]

In[2]: Subscript[lay,4]
Out[2]:matg[[4]].hl[[3]] + matg[[3]].matg[[4]].hl[[2]] +
matg[[2]].matg[[3]].matg[[4]].hl[[1]] + hl[[4]]

However, I need to get the right code of the above, so that the output that Iam looking will look like this,

In[3]: Subscript[lay,3]
Out[3]: matg[[3]].hl[[2]] + matg[[3]].matg[[2]].hl[[1]] + hl[[3]]

In[4]: Subscript[lay,4]
Out[4]: matg[[4]].hl[[3]] + matg[[4]].matg[[3]].hl[[2]] +
matg[[4]].matg[[3]].matg[[2]].hl[[1]] + hl[[4]];


As you can see the above pattern, I wish the output (the number in the bracket of matg) to be arranged in desecending order.

Please help me to modify the above code and many thanks for any kind helps.

Note: Please ignore the warnings given by the mathematica
PhysOrg.com science news on PhysOrg.com

>> City-life changes blackbird personalities, study shows
>> Origins of 'The Hoff' crab revealed (w/ Video)
>> Older males make better fathers: Mature male beetles work harder, care less about female infidelity
Jun17-12, 02:56 PM   #2
 
You have to generate factors in reverse order. Just change arguments in Table command:

Code:
term[n_Integer,m_Integer]:=Apply[Dot,Table[matg[[i]],{i,n,m+1,-1}]].hl[[m]]/;(n>=m);
Subscript[lay,s_]:=Sum[term[s,i],{i,s}];
Jun18-12, 02:32 AM   #3
 
It works...Thank you so much.
New Reply

Similar discussions for: Mathematica: Need help to modify the code
Thread Forum Replies
[Mathematica] How to use this code? Math & Science Software 0
looking for a generic code using Mathematica Math & Science Software 10
Mathematica source code... Math & Science Software 1
How to modify the following code? Programming & Comp Sci 3
Mathematica code help Math & Science Software 24