Solving Systems with Iteration in Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter nikolafmf
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary

Discussion Overview

The discussion revolves around solving a system of equations using iteration in Mathematica, specifically focusing on the manipulation of matrices and iterative computations. Participants explore how to set up and execute iterations to update matrix values based on previous outputs.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant describes a process involving 4×1 matrices and a 4×4 matrix, aiming to solve for a vector f in the equation u=V.f, and subsequently define a vector g based on f and a time variable t.
  • Another participant mentions discovering the use of the Do function for iterations but struggles with updating input values based on the last output.
  • A participant shares their code and expresses frustration that Mathematica does not seem to update the variable u with the new value of p as intended.
  • One participant corrects mistakes in the initial code and provides a working example, demonstrating the use of LinearSolve and suggesting a more concise way to compute g using mapping functions.
  • There is a question raised about the difference in results between using matrix inversion and LinearSolve, indicating a potential area of confusion or misunderstanding.

Areas of Agreement / Disagreement

Participants express varying levels of understanding and approaches to the problem, with some agreeing on the utility of certain functions while others remain uncertain about specific aspects of the implementation. The discussion does not reach a consensus on the best method for updating variables or the differences in results from different methods.

Contextual Notes

Participants note limitations in Mathematica's documentation regarding complex iterative processes and express the need for more specific guidance in their coding challenges.

Who May Find This Useful

This discussion may be useful for individuals working with Mathematica on iterative matrix computations, particularly those interested in solving systems of equations and updating values based on previous iterations.

nikolafmf
Messages
112
Reaction score
0
What I want to do with Mathematica is this:

1. Given are 4×1 matrices e and u, and 4×4 matrix V. Matrices e and V are constant.
2. Solve the system u=V.f for f, where f is 4×1 matrix.
3. Define 4×1 vector g such as g1=f1*Exp(e1*t), g2=f2*Exp(e2*t) etc, where g1 is the first component of g, f1 is the first component of f, e1 is the first component of e etc and t=0.1 or 1 or whatever small number.
4. Compute p, where p=V.g
5. Print p and t*(the number of current step in the iteration)
6. Redefine u=p and do it all over again.

Mathematica gives examples where only one expression is to be computed, while I want to compute more expressions in one step. I have no idea how to tell Mathematica to do this. Any idea will be appreciated. You can also give me (if you know one) a link or a title of a book where such kind of problems are explained.

Please help :)
 
Physics news on Phys.org
Ok, I have found out how iterations could be made with function Do. But one problem I can't solve is this: how to tell Mathematica the new input to be equal to the last output? It seems that Mathematica doesn't change the input at all. Also, how to print the number of the step of the iteration?
 
Here is my code. At the end I have written u:=p, to tell Mathematica to start the next step with last result. But it won't :(

Do[u := ({
{152100000},
{0},
{0},
{29290}
}); f = LinearSolve[V, u]; g := ({
{Part[f, 1]*Exp[Part[e, 1]*10]},
{Part[f, 2]*Exp[Part[e, 2]*10]},
{Part[f, 3]*Exp[Part[e, 3]*10]},
{Part[f, 4]*Exp[Part[e, 4]*10]}
}); p := V.g; Print[p]; u := p, {10}]
 
Fix a number of mistakes

In[1]:= e={1.,2.,3.,4.};
V={{1,2,6,3},{6,1,5,4},{3,5,2,7},{8,4,5,1}};
u={152100000,0,0,29290};
Do[
f=LinearSolve[V,u];
g={Part[f,1]*Exp[Part[e,1]*10], Part[f,2]*Exp[Part[e,2]*10], Part[f,3]*Exp[Part[e,3]*10], Part[f,4]*Exp[Part[e,4]*10]};
p=V.g;
Print[p];
u=p,
{10}
]

From In[1]:= {-3.796667*^24, -5.063140*^24, -8.862560*^24, -1.264638*^24}
From In[1]:= {-8.941114*^41, -1.192148*^42, -2.086260*^42, -2.980371*^41}
From In[1]:= {-2.104606*^59, -2.806142*^59, -4.910749`*^59, -7.01535*^58}
From In[1]:= {-4.953934*^76, -6.605245*^76, -1.155917*^77, -1.651311*^76}
From In[1]:= {-1.166083*^94, -1.554777*^94, -2.720860*^94, -3.886943*^93}
From In[1]:= {-2.744787*^111, -3.65971*^111, -6.40450*^111, -9.14929*^110}
From In[1]:= {-6.460826*^128, -8.61443*^128, -1.50752*^129, -2.15360*^128}
From In[1]:= {-1.520783*^146, -2.02771*^146, -3.54849*^146, -5.06927*^145}
From In[1]:= {-3.579699*^163, -4.77293*^163, -8.35263*^163, -1.19323*^163}
From In[1]:= {-8.426086*^180, -1.12347*^181, -1.96608*^181, -2.80869*^180}

You can also simplify your code using some features of Mathematica using

g=f Map[Exp[#*10]&,e];

instead of

g = {Part[f, 1]*Exp[Part[e, 1]*10], Part[f, 2]*Exp[Part[e, 2]*10], Part[f, 3]*Exp[Part[e, 3]*10], Part[f, 4]*Exp[Part[e, 4]*10]};

I wonder why this

f = u.Inverse[V];

produces results that are not the same as this

f = LinearSolve[V, u];
 
Last edited:
Thank you very, very much.

Although Mathematica has good help, it has no advice for any situation one may come in :(

Thank you
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 3 ·
Replies
3
Views
4K