Formula

for i:=1 to n do begin Y[i]:=(D1*Y[i-1])+(D2*X[i])+D3*Z[i]; Z[i]:=(Z[i-1]*D4)+(D5*Y[i]); end; 

Error in the calculation, since at the i step of the cycle, when trying to calculate the value of Y [i], there is still no value for the variable Z [i], and when calculating the value of Z [i] the wrong value of Y [i] is used. In this case, Excel formula correctly calculates. Link to Excel document https://yadi.sk/i/3Y2kTR2ErTgBg

    2 answers 2

    If I understand the problem correctly, there is simple math. The condition consists of two equations in which there are only two unknowns: y[i] and z[i] .

     y[i] = y[i-1]*d1 +x[i]*d2 + z[i]*d3 z[i] = z[i-1]*d4 + y[i]*d5 

    And such things are solved very easily, by substituting the expression from the first equation into the second.

    Watch your hands:

    1. Instead of y[i] , we substitute its value into the second equation:

    z[i] = z[i-1]*d4 + d5*(y[i-1]*d1 +x[i]*d2 + z[i]*d3)

    1. We divide both sides of the equation by d5 :

    z[i]/d5 = z[i-1]*d4/d5 + y[i-1]*d1 +x[i]*d2 + z[i]*d3

    1. Transferring z[i]*d3 to the left:

    z[i]/d5 - z[i]*d3 = z[i-1]*d4/d5 + y[i-1]*d1 +x[i]*d2

    1. Multiply back by d5 :

    z[i] - z[i]*d3*d5 = z[i-1]*d4 + (y[i-1]*d1 +x[i]*d2)*d5

    1. In the left part we put z[i] for the brackets:

    z[i]*(1 - d3*d5) = z[i-1]*d4 + (y[i-1]*d1 +x[i]*d2)*d5

    1. We divide both parts by (1 - d3*d5) :

    z[i] = (z[i-1]*d4 + (y[i-1]*d1 +x[i]*d2)*d5) / (1 - d3*d5)

    And now we know how to calculate z[i] , which does not depend on y[i] .

    Therefore, the solution is:

     // инициализация for i := 0 to n do begin x[i] := ??? end; y[0] := ??? z[0] := ??? // вычислСниС for i := 1 to n do begin z[i] := (z[i-1]*d4 + (y[i-1]*d1 +x[i]*d2)*d5) / (1 - d3*d5); y[i] := y[i-1]*d1 +x[i]*d2 + z[i]*d3; end; 

      You need to initialize the variables:

       Y[0]:=0; Z[0]:=0; 

      Since it is necessary to calculate the value of both variables Y[i] and Z[i] at the same time, we will carry out a simple mathematical transformation. We introduce a variable C equal to

       C = Y[i] - Z[i]*D3 

      We get:

       Z[i] = Z[i-1]*D4 + (C + Z[i]*D3)*D5 

      That is, Z[i] is

       Z[i] = (Z[i-1]*D4 + C*D5) / (1 - D3*D5) 

      Now let's rewrite the calculation algorithm:

       for i:=1 to n do begin Π‘:=(D1*Y[i-1])+(D2*X[i]); Z[i]:=(Z[i-1]*D4+D5*Π‘)/(1-D3*D5); Y[i]:=Π‘+D3*Z[i]; end; 
      • when calculating D3 * Z [i] will give 0 a reference to the calculation in Exel yadi.sk/i/3Y2kTR2ErTgBg - Dima Kaminskiy
      • This is not Excel, but Pascal. Variables must be initialized before use. - Vanyamba Electronics
      • I laid out a piece of code, all variables are initialized. The question is how to do the calculation of variables at the same time. - Dima Kaminskiy