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

In summary, the author has difficulties applying the "Do Loop" command, but if he does it manually, without using the Do command, he gets a quicker output. However, the author is unhappy because there is no "diff" utility that can overlook meaningful differences between two versions of a file.
  • #1
kaizen.moto
98
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

  • ManualCodes.nb
    132.2 KB · Views: 404
  • DoLoop.nb
    160.9 KB · Views: 426
Physics news on Phys.org
  • #2
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.
 
  • #3
Did you test this code in short segments to see if it even works?
Break it down section by section?
 
  • #4
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.
 
  • #5
for reaching out for help with your Do-loop in Mathematica. I understand that it is taking a long time to run and you are looking for a more efficient solution.

One potential solution is to use the NestList or NestWhileList functions instead of a Do-loop. These functions allow you to iterate a function over a list of values and can often be faster than a Do-loop. Another option is to parallelize your code using the ParallelDo or ParallelTable commands, which can speed up the computation by utilizing multiple processors.

Additionally, you may want to consider breaking your large matrix into smaller chunks and using the Do-loop on each chunk separately. This can also help speed up the computation time.

I hope these suggestions help and that you are able to find a more efficient solution for your problem. Best of luck!
 

1. How do I use Do-loop to solve large matrices in Mathematica?

To use Do-loop in Mathematica, you need to first define the variables and conditions for the loop. Then, use the Do keyword followed by the commands to be executed inside the loop. Finally, use the While or For keyword to specify the condition for the loop to continue. Make sure to use the correct syntax and indentation to avoid errors.

2. Can Do-loop be used for matrices of any size?

Yes, Do-loop can be used for matrices of any size in Mathematica. However, it is important to note that the larger the matrix, the longer it may take to compute. It is also important to optimize the code and use efficient algorithms to minimize computation time.

3. How can I optimize the performance of Do-loop for large matrices?

To optimize the performance of Do-loop for large matrices, you can try using parallel computing techniques or built-in functions specifically designed for matrix operations in Mathematica. You can also use vector operations instead of scalar operations to improve efficiency.

4. Are there any alternatives to Do-loop for solving large matrices in Mathematica?

Yes, there are other alternatives to Do-loop for solving large matrices in Mathematica. Some of these include built-in functions such as MatrixPower and LinearSolve, as well as specialized packages like the LinearAlgebra`MatrixManipulation` package. It is recommended to explore these alternatives and choose the most suitable one for your specific problem.

5. How can I troubleshoot errors while using Do-loop for large matrices?

If you encounter errors while using Do-loop for large matrices in Mathematica, you can try checking the syntax and indentation of your code, as well as the conditions specified for the loop. You can also try breaking down the problem into smaller steps and testing each step individually. Additionally, consulting the Mathematica documentation or seeking help from online forums can also be helpful in troubleshooting errors.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
9K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
8K
  • Programming and Computer Science
Replies
1
Views
612
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
7K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
Back
Top