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


  • $\begingroup$ Should this really be here, and not a programming forum? $\endgroup$ – GEdgar Aug 29 '11 at 20:56
  • $\begingroup$ As it stands, it's unanswerable since you didn't say what the ai and Qk are. Are you trying to do Runge-Kutta by any chance? $\endgroup$ – J. M. is a poor mathematician Aug 30 '11 at 2:13
  • $\begingroup$ Could you write the original differential equations? $\endgroup$ – tlehman Aug 30 '11 at 14:13
  • $\begingroup$ GEdgar, yes it should be here, because it is a numerical method for solving differential equation $\endgroup$ – derdack Aug 30 '11 at 16:00
  • $\begingroup$ J.M. I wrote that ai and Qk are the function of the x I mean (delta x). This is not a Runge Kutta. habitmelon original differential equation is R1*q''(x)+R2*q'[x]+R3*q[x]=F(x), Ri contants, but I don`t want another method for solving. Just help about programing in mathematica for simple iteration which I wrote. $\endgroup$ – derdack Aug 30 '11 at 16:17

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

     calculate Q's
     qp=  (using qold for q[j])
     qpp= (using qold for q[j])
  • 1
    $\begingroup$ Mathematica also supports so-called "dynamic programming": e.g. f[0] = 1; f[n] := f[n] = n f[n-1] for the factorial, which I believe the OP wanted to do for his particular system. Still, the question is less than clear to me... $\endgroup$ – J. M. is a poor mathematician Aug 30 '11 at 13:22
  • $\begingroup$ @J.M.: That should read f[0] = 1; f[n_Integer?Positive] := f[n] = n f[n-1] $\endgroup$ – Simon Aug 30 '11 at 22:18
  • $\begingroup$ @Simon: Yes, I forgot the _ (and the head-checking for guaranteed correctness); thanks! $\endgroup$ – J. M. is a poor mathematician Aug 30 '11 at 22:20
  • $\begingroup$ Dear Ross Millikan how can I set the step of delta{x}, because for example I have a2=1/delta{x}. I need from [0,1] for each delta{x} with step 0.01 value of q. Regards! $\endgroup$ – derdack Aug 31 '11 at 14:33
  • $\begingroup$ Usually your steps are in x, not q. You choose delta x, say as .01, or choose 1000 steps in [0,1] and find delta x is .001. Then the steps in q are calculated. You start with initial conditions q(0), q'(0). Usually your iteration starts with q'' as a function of q, q' and x. Then you step up to q'(delta x) and q(delta x). Then you use your equation to get q''(2 delta x), q'(2 delta x), q(2 delta x), etc. $\endgroup$ – Ross Millikan Aug 31 '11 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.