How to make simple iteration in Mathematica

2.8k Views Asked by At

How to make simple iteration in Mathematica for this three equations and save $q$ for each step. If we define $q'=dq/dx$, $q''=dq'/dx$ we have two equations

(1) $q''[j+1]=a_1(q[j+1]-q[j])-a_3q'[j]-a_5q''[j]$,

(2) $q'[j+1]=a_2(q[j+1]-q[j])+a_4q'[j]+a_6q''[j]$,

And we should substitute in third

(3) $q[j+1]=Q_2q[j]+Q_3q'[j]+Q_4q''[j]$

$a_i$ and $Q_k$ ($i=1,\ldots,6$; $k=1,2,3$) are functions of $\delta(x)$. Where $\delta(x)=0.01$ for example. For each $\delta(x)$ I need $q$.

Regards,

1

There are 1 best solutions below

20
On BEST ANSWER

You can just use a For loop, following the manual. Equation 3 has no [j+1] on the right, so should be calculated first. Then equations 1 and 2 can be calculated as you already have q[j+1].

For[j=0,j<end,j++,
     calculate Q's
     qold=q
     q=
     qp=  (using qold for q[j])
     qpp= (using qold for q[j])
     Print[j,q,qp,qpp]