Help me to solve Do-loop for large matrices (Mathematica)

  • Context: Mathematica 
  • Thread starter Thread starter kaizen.moto
  • Start date Start date
  • Tags Tags
    Mathematica Matrices
Click For Summary

Discussion Overview

The discussion revolves around the performance issues encountered when using the Do-loop command in Mathematica for large matrices. Participants explore the differences in execution time between using a Do-loop and manual input of variable values, as well as the errors that arise when attempting to implement the Do-loop.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Experimental/applied

Main Points Raised

  • One participant reports that the Do-loop command takes excessively long to run, exceeding 24 hours, while manual execution yields quick results.
  • Another participant notes encountering errors related to SetDelayed and suggests that these errors indicate underlying issues that need to be identified and resolved.
  • A participant questions whether the code has been tested in segments to verify its functionality, implying that breaking it down could help isolate problems.
  • The original poster asserts that all code segments work correctly without errors when run individually and that the issue is specifically with the Do-loop's performance.
  • The original poster seeks suggestions for improving the code or modifying the syntax to enhance performance.

Areas of Agreement / Disagreement

Participants do not appear to reach a consensus on the cause of the performance issues or the errors encountered. Multiple views on troubleshooting and code optimization are present, with no clear resolution offered.

Contextual Notes

There are limitations in tracking down errors due to the complexity and size of the Mathematica notebooks involved. The discussion also highlights potential differences in behavior across different versions of Mathematica.

Who May Find This Useful

Individuals working with large matrices in Mathematica, particularly those interested in optimizing code performance and troubleshooting errors related to Do-loops.

kaizen.moto
Messages
94
Reaction score
0
Hi all,

I have difficulties about applying the Do-loop command as it takes very long time to run (more than 24 hours and it keeps running).

However, if i do it manually, without Do command, i.e. putting the values of the variables, Mathematica gives me a pretty quick output.

Please see the attached files.

I really appreciate for any comments.


Thanks
 

Attachments

Physics news on Phys.org
When I evaluate the "Do loop" version I see errors

SetDelayed::write: Tag Times in Pi/a[m_] is Protected.
SetDelayed::write: Tag Times in Pi/a[n_] is Protected.
followed by a variety of other SetDelayed and Part errors.

That very likely indicates something is wrong and needs to be tracked down.

But given two notebooks over a hundred kilobytes each with a variety of changes in format and organization makes it very difficult to try to track down what is wrong.

It is unfortunate, but I don't believe there is a "diff" utility that understands Mathematica notebooks and can overlook meaningless differences while pointing out significant differences. I can manually find some of the things you have changed to turn one into the other but I have not been able to track down exactly what was broken in changing from the "manual" to the "do" version.

If this were mine I would track down and figure out and fix what was causing those errors. I would begin at the top of the two files and track down what changes you have made are important, what are not, and where errors have been introduced.
 
Did you test this code in short segments to see if it even works?
Break it down section by section?
 
I have run and checked all the codes, segment by segment by breaking them into an indvidual cell, they are all working fine and give me the outputs without any errors or warning.

I don't have such errors displayed when I run the codes using version 7 (both windows and linux machines).

My problem is only that the Do-loop version takes such a very long time to run and still I don't have any output. I need some suggestions if there is any way to improve my codes or any modifications in the syntax/command that need to be replaced.

I welcome any comments and really appreciate it.

Thank you.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 21 ·
Replies
21
Views
6K
Replies
3
Views
4K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 13 ·
Replies
13
Views
8K
  • · Replies 6 ·
Replies
6
Views
10K
  • · Replies 6 ·
Replies
6
Views
8K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K