- #1

- 98

- 0

You are using an out of date browser. It may not display this or other websites correctly.

You should upgrade or use an alternative browser.

You should upgrade or use an alternative browser.

- Mathematica
- Thread starter kaizen.moto
- Start date

- #1

- 98

- 0

- #2

- 313

- 1

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...

- #3

- 1,069

- 29

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

- #4

- 98

- 0

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

- #5

- 98

- 0

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

really appreciate it.

- #6

- 313

- 1

I dont 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.

Share:

- Replies
- 1

- Views
- 2K

- Replies
- 1

- Views
- 3K

- Replies
- 1

- Views
- 3K

- Replies
- 10

- Views
- 4K

- Replies
- 1

- Views
- 2K