Seeded iteration MathCad Help

Seeded iteration is a recursive technique for solving difference equations such as those that arise in compound interest problems, Markov processes, and many state variable equations. It can also be used for obtaining approximate solutions for certain differential equations. In a seeded iteration, you specify the first element of an array and then compute successive elements based on the first element. This section describes three types of seeded iteration: iterating a single variable, iterating multiple variables, and iterating a vector.

Seeded iteration on one variable

The classical method for estimating square roots arithmetically is as follows

• To find Ja, begin with a guess value.
• Compute a new guess based on the old guess, with this formula:

Seeded iteration

Seeded iteration

Continue until the guesses converge to an answer.
Figure 11-10 shows how to implement this method in Mathcad

Using seeded iteration to estimate a square root.

Using seeded iteration to estimate a square root.

The important characteristics of this example are:
• The-seed value is defined as the zeroth element of the array,
• Each is defined in terms of a previously computed element.

It is this dependence of array elements on previously computed array elements that distinguishes seeded iteration from the more straightforward iteration discussed in the previous section.

Seeded iteration on several variables

You can use Mathcad’s vector notation to iterate several variables simultaneously. This variation on simple seeded iteration is a powerful method for solving a system of simultaneous difference equations.

When you iterate several variables, each step computes the value of the variables from all of their previous values. You can’t accomplish this with several equations because when Mathcad sees an equation with range variables, it attempts to evaluate it for each value of the range variable before going on to the next equation. You must, therefore, create one equation that performs all the iterations simultaneously.

For example, consider an infection model with four variables: i for the number of individuals infected, s for the number susceptible, d for the number deceased, and r for the number recovered and hence immune. The four equations that relate these four variables over time are:

shows how to perform a simultaneous iteration using these equations.

shows how to perform a simultaneous iteration using these equations.

The single most important thing about this example is that all the t + 1 subscripts are on the left-hand side of the matrix equation. The right-hand side contains only the subscript t. Mathcad evaluates all the expressions on the right-hand side before performing any assignments to the left-hand side. This means that nothing on the right hand side can depend on something on the left-hand side.

Simultaneous iteration to model an infection.

Simultaneous iteration to model an infection.

Seeded iteration on a vector

You can also perform seeded iteration starting with a vector and computing a new vector each time. This type of iteration uses a seed vector and Mathcad’s superscript operator.

A Markov process is an example of a problem that involves iteration on a vector. A Markov process begins with a vector v that represents the starting values of some quantities, for example, the number of voters planning to vote for different candidates, the number of trucks at regional offices of a truck rental company, or the market share of different companies. Each step in the Markov process computes a new vector by multiplying the previous vector by a “state transition” matrix A

Figure 11-12 shows how to set up a Markov process. This technique uses superscripts to index an entire column of a matrix at once. To create a superscript, press [Ctrl]6. This generates a placeholder between angle brackets: < >.

Here’s how to enter the equations in Figure 11-12:

• First, define the state transition matrix A. Type A, press the colon key ( : ), and create a 3 x 3 matrix. To create a matrix, choose Matrix from the Insert menu

Seeded iteration on a vector1

Seeded iteration on a vector1

• Click to the right of the matrix and type v. Then press [Ctrl]6. Type in the placeholder for the superscript.

Seeded iteration on a vector1

Seeded iteration on a vector1

• Now complete the definition of the initial vector. First press the colon key ( : ). Then choose Matrix from the Insert menu. Specify that you want to create a matrix with three rows and one column. Then fill  in the matrix entrie

Seeded iteration on a vector1

Seeded iteration on a vector1

• Type k: 1; 8. This defines a range variable k to count eight iterations

Seeded iteration on a vector1

Seeded iteration on a vector1

The superscript operator actually retrieves or defines one column in a matrix. When you define in terms of , you are actually defining each column of a matrix in terms of the preceding column. The last equation in Figure 11-12 shows the matrix composed from these columns

Iterating a vector to model a Markov process,

Iterating a vector to model a Markov process,

Posted on November 20, 2015 in Range Variables

Share the Story

Back to Top
Share This