Mathematica: please from the experts

  • Mathematica
  • Thread starter kaizen.moto
  • Start date
  • Tags
    Mathematica
In summary: So, the expressions you are trying to sum are definitely linear. However, I cannot help you with the rest of your question because I do not understand it.
  • #1
kaizen.moto
98
0
Dear all,

Please help me to fix this problem:

f[m_, n_] :=
Module[{u1, u2, v1, v2, sumu1, sumu2, sumv1, sumv2}, u1 = 3 m + 2 n;
u2 = 2 m - 5 n; v1 = 4 m - 3 n; v2 = 6 m + 3 n;
sumu1 = Sum[u1[i, n], {i, 1, m, 2}];
sumu2 = Sum[u2[i, n], {i, 1, m, 2}];
sumv1 = Sum[v1[m, j], {j, 1, n, 2}];
sumv2 = Sum[v2[m, j], {j, 1, n, 2}] {sumu1, sumu2, sumv1, sumv2}];

Do[f[m, n]; Print[f[m, n]], {m, 1, 3, 2}, {n, 1, 3, 2}]

Definitions: the idea is that sumu1(1,1) = u1(1,1); sumu1(1,3) = u1(1,3); sumu1(3,1) = u1(1,1) + u1(3,1); sumu1(3,3) = u1(1,3) + u1(3,3)

and for sumu2(1,1) = u2(1,1); sumu2(1,3) = u2(1,3); sumu2(3,1) = u2(1,1) + u2(3,1); sumu2(3,3) = u2(1,3) + u2(3,3)

However for sumv1(1,1) = v1(1,1); sumv1(1,3) = v1(1,1) + v1(1,3); sumv1(3,1) = v1(3,1) ; sumv1(3,3) = v1(3,1) + v1(3,3)

and similarly for sumv2(1,1) = v2(1,1); sumv2(1,3) = v2(1,1) + v2(1,3); sumv2(3,1) = v2(3,1) ; sumv2(3,3) = v2(3,1) + v2(3,3)


The correct answers I should be getting from the Do-loop are:

f(1,1) = { 5, -3 , 1 , 9}
f(1,3) = { 9 , -13 , -4 , 24 }
f(3,1) = {15 , -2 , 11 , 19 }
f(3,3) = { 24 , -22 , -2 , 42 }

Thank you for any kind help.
 
Physics news on Phys.org
  • #2
kaizen.moto said:
The correct answers I should be getting from the Do-loop are:

f(1,1) = { 5, -3 , 1 , 9}
f(1,3) = { 9 , -13 , -4 , 24 }
f(3,1) = {15 , -2 , 11 , 19 }
f(3,3) = { 24 , -22 , -2 , 42 }
Are you sure these are correct?

Try this:
Code:
u = {{3, 2}, {2, -5}};
v = {{4, -3}, {6, 3}};
f[m_, n_] :=
 Module[{sumu, sumv},
  sumu = Sum[u.{i, n}, {i, 1, m, 2}];
  sumv = Sum[v.{m, j}, {j, 1, n, 2}];
  Flatten[{sumu, sumv}]
];
Do[Print[f[m, n]], {m, 1, 3, 2}, {n, 1, 3, 2}]
 
  • #3
Apologise for my mistakes. You are absolutely right. Your revised code is working perfectly for the above simplified exercise.

However, due to the real application, working your code with my case, its not practical. One of the reasons, my actual expression for u1, u1, v1 and v2 consisting of variables m and n (and also some other constants) are quite lengthy. Its going to be tedious to rerrange them collectively in a single expression (such as u={{3,2},{2,-5}).

I still prefer to express u and v in a separate terms, i.e. u1, u2, v1 and v2 as per my original version.

I have tried to use your suggested code but it gives funny looking outputs.

f[m_, n_] :=
Module[{u1, u2, v1, v2, sumu1, sumv1, sumu2, sumv2}, u1 = 3 m + 2 n;
u2 = 2 m - 5 n; v1 = 4 m - 3 n; v2 = 6 m + 3 n;
sumu1 = Sum[u1.{i, n}, {i, 1, m, 2}];
sumv1 = Sum[v1.{m, j}, {j, 1, n, 2}];
sumu2 = Sum[u2.{i, n}, {i, 1, m, 2}];
sumv2 = Sum[v2.{m, j}, {j, 1, n, 2}];
Flatten[{sumu1, sumu2, sumv1, sumv2}]];
Do[Print[f[m, n]], {m, 1, 3, 2}, {n, 1, 3, 2}].

Is there any other way, to get the right code?
 
  • #4
kaizen.moto said:
However, due to the real application, working your code with my case, its not practical. One of the reasons, my actual expression for u1, u1, v1 and v2 consisting of variables m and n (and also some other constants) are quite lengthy.
Are the expressions always linear, as in this example?

kaizen.moto said:
Is there any other way, to get the right code?
Of course. There are always an infinite number of ways.
 
  • #5
all the expressions of u1, u2..., v1, v2,... consists of non linear equation. In fact, some of them have a high very degree of polynomial expressions. Actually, I was trying to get a single expression of u or v in terms of other variables including m, n and other constants from Mathematica, but it took me ages to get this expression. The program is still running for many hours to get u's and v's. From this fact, that u's and v's are pretty much high degree polynomial of m and n variables.

In the meantime, Iam tyring to express u's and v's interms of a function such as u1[m_,n_]:=...v1[m_,n_]:=...inside the Module.

I hope it could be done.
 
  • #6
kaizen.moto said:
all the expressions of u1, u2..., v1, v2,... consists of non linear equation. In fact, some of them have a high very degree of polynomial expressions.
I am a little confusesd by this response. Polynomials of any order are linear. The sum of two polynomials of order k is a polynomial of order k, and the product of a scalar and a polynomial of order k is a polynomial of order k.

The reason that I ask is that if you can cast your problem in terms of a system of linear equations then you open the door to the use of some very powerful pre-packaged computer techniques:

http://en.wikipedia.org/wiki/System_of_linear_equations

kaizen.moto said:
In the meantime, Iam tyring to express u's and v's interms of a function such as u1[m_,n_]:=...v1[m_,n_]:=...inside the Module.

I hope it could be done.
Certainly, it can be done. You just cannot use m and n as your variables since those are already being used by f. Use, e.g. u1[a_,b_]:=... instead. Alternative you can change f so that it doesn't use m and n, the point is that you need to avoid the conflict between the two.
 
Last edited:
  • #7
I've got it finally, the code is working now with Module.

Again, thank you so much for your relentless support and guidance. You are a very nice person...you deserve more medals...
 
  • #8
Thanks, and I am still available for hire to program it. :smile:
 
  • #9
can I have your e-mail address please, if you don't mind...
 

1. What is Mathematica and what is it used for?

Mathematica is a computational software program used for mathematical, scientific, and engineering computations. It is commonly used for data analysis, visualization, and modeling, as well as for solving complex mathematical and scientific problems.

2. How does Mathematica handle symbolic and numerical calculations?

Mathematica has the ability to handle both symbolic and numerical calculations. It uses advanced algorithms and built-in functions to perform symbolic manipulations and exact calculations, while also providing high-precision numerical approximations.

3. Can Mathematica be used for programming and creating custom functions?

Yes, Mathematica has a built-in programming language called Wolfram Language, which allows users to create custom functions, automate tasks, and develop complex programs. It also supports various programming paradigms, such as functional, procedural, and object-oriented programming.

4. Is Mathematica user-friendly for beginners?

While Mathematica may have a steep learning curve for beginners, it provides a user-friendly interface and comprehensive documentation to help users get started. There are also numerous online resources and communities available for support and learning.

5. Can Mathematica be used for data analysis and visualization?

Yes, Mathematica has powerful data analysis and visualization capabilities. It can handle large datasets, perform statistical analysis, and create interactive and high-quality visualizations. It also has built-in tools for data cleaning, manipulation, and transformation.

Similar threads

  • Mechanical Engineering
Replies
2
Views
990
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
4K
  • Set Theory, Logic, Probability, Statistics
Replies
20
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • Mechanical Engineering
Replies
1
Views
1K
  • Introductory Physics Homework Help
Replies
3
Views
1K
  • Programming and Computer Science
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
9K
Back
Top