# Can someone me on this problem using Mathematica

• Mathematica
• kaizen.moto
In summary, your equations all look linear -- can you not rewrite the system using matrices? You can construct your matrices of unknowns using Array[] or SparseArray[] and maybe Band[] etc...Perhaps instead of Do[] you could try Table[] or Reap[] and Sow[] instead. You might also want to look at some of the other options for solving simultaneous equations and summation together that are available in Mathematica.

#### kaizen.moto

Hi all,

Please help me to improve the syntax which involving Do-loop function and solving simultaneous equations and summation together.

the answer should match with the one given in the following cell.

Many thanks for any feeback.

#### Attachments

• Exercise2.nb
22.5 KB · Views: 408
That's really ugly! Where did this system of equations come from?

All your equations look linear -- can you not rewrite the system using matrices?

You can construct your matrices of unknowns using Array[] or SparseArray[] and maybe Band[] etc...

Do[...,{m,1,3,2},{n,1,3,2},{r,0,15,1}];Sum[jjj1[0],{m,1,3,2},{n,1,3,2}]/.{...}

consider

Table[Sum[...;jjj1[0]/.{...},{m,1,3,2},{n,1,3,2}],{r,0,15,1}]

so you can put the work for Solve inside the Sum and have the expression you want to Sum as the last item before your Sum indicies and then you create a Table of all the needed Sums.

FORTRAN and C and BASIC have drilled into people that they must use Do or For. But in Mathematica it is sometimes better to accomplish this using Table.

So the alternative I wrote above, instead of Doing something 16 times, you create a Table to hold the 16 results. Each of those results will be your Sum over m and n. Once you have that Table you can then use Total to add up all the jjj1 values if needed.

If you wish to continue using Do and For then there is a method to accomplish this using Reap and Sow.

Reap[ Do[x=y+2;etc;etc;Sow[x],{n,1,3,2}]][[2,1]]

Any time anywhere inside your Do or For you can Sow an expression, even multiple times. All those values will be concatenated into a list and when the Do is finished the Reap will give you the list of values. The [[2,1]] discards some extra information that Reap and Sow also put in there that you may or may not need.

So see if you can move your Sum inside a Table or use Reap and Sow.

If you need more help then try to explain how you need this changed and I'll see what I can do

I don't ask for any judgement how beautiful or ugly my syntax or equations are in this forum. As a new user of Mathematica, I want to learn how to use it in programming.

I really appreciate for the positive comment anyway. I would try to apply as per recommendations, thanks.

Hi Bill,

I got it now, you are so genius. Thanks a lot for your kind help. You save my day. It works at your first recommendation.

really appreciate it.

kaizen.moto said:
I don't ask for any judgement how beautiful or ugly my syntax or equations are in this forum. As a new user of Mathematica, I want to learn how to use it in programming.

I meant no offence by the ugly comment. It's just that code that "looks ugly" normally means that it's not optimal in any way. Neither efficient, understandable nor concise.

My comment about where the system came from was related and relevant -- in systems like Mathematica, it's normally best if your code can reflect the underlying logic of the problem as much as possible. A whole heap of Do[] loops rarely reflects how you should think about a math problem.

## 1. Can someone teach me the basics of using Mathematica?

Yes, there are many resources available for learning the basics of Mathematica, including online tutorials, textbooks, and classes. You can also ask for help on online forums or seek assistance from colleagues who are experienced with the software.

## 2. How can I get help with a specific problem using Mathematica?

If you are facing a specific problem while using Mathematica, you can search for solutions on online forums or consult the documentation provided by the software. You can also ask for assistance from colleagues or seek professional help from experts in the field.

## 3. How can I improve my skills in using Mathematica?

The best way to improve your skills in using Mathematica is to practice regularly and explore the various functions and capabilities of the software. You can also attend workshops or classes, participate in online communities, and read advanced textbooks to deepen your understanding.

## 4. Can Mathematica be used for data analysis and visualization?

Yes, Mathematica has powerful capabilities for data analysis and visualization. It has built-in functions for importing, cleaning, and manipulating data, as well as creating various types of visualizations such as charts, graphs, and plots.

## 5. Is Mathematica suitable for solving complex mathematical problems?

Yes, Mathematica is commonly used for solving complex mathematical problems, such as differential equations, optimization, and statistics. It has a wide range of built-in functions and algorithms that can handle advanced mathematical computations efficiently.