Mathematica: Need help to modify the code

In summary, the conversation involved someone asking for help to edit their code to match a specific output arrangement. They provided examples and asked for assistance in modifying the code to achieve the desired result. The expert suggested changing the arguments in the Table command to generate factors in reverse order, which solved the issue. The person expressed gratitude and the conversation ended.
  • #1
kaizen.moto
98
0
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, 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
 
Physics news on Phys.org
  • #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}];
 
  • #3
It works...Thank you so much.
 

FAQ: Mathematica: Need help to modify the code

How can I modify the code to perform a specific calculation?

To modify the code in Mathematica, you can use the built-in functions and operators to manipulate the data and perform the desired calculation. You can also write your own custom functions to perform specific tasks.

Can I modify the code to work with a different data set?

Yes, you can modify the code to work with a different data set by changing the input data or using different variables and parameters in your code. You can also use functions like Import to read in data from external sources.

How do I troubleshoot errors when modifying the code?

If you encounter errors when modifying the code, try checking for syntax errors or using the built-in debugging tools in Mathematica. You can also refer to the documentation or seek help from online forums or communities.

Can I modify the code to create custom visualizations?

Yes, you can modify the code to create custom visualizations by using functions like Plot or ListPlot to display data in different formats. You can also use built-in graphics and formatting options to customize the appearance of your visualizations.

Is it possible to modify the code to work with real-time data?

Yes, you can modify the code to work with real-time data by using functions like Dynamic or Manipulate to update the data and visualizations in real-time. You can also use external libraries or APIs to retrieve and process real-time data in your code.

Similar threads

Replies
10
Views
4K
Replies
2
Views
693
Replies
1
Views
2K
Replies
1
Views
811
Replies
2
Views
2K
Replies
13
Views
2K
Replies
1
Views
1K
Replies
2
Views
2K
Back
Top