ITERATE: Difference between revisions

From iMath
Jump to navigation Jump to search
No edit summary
No edit summary
Line 13: Line 13:
It is highly recommended to set the maximum number of iterations to a very low value when testing new expressions. If for some reason the expression on the right-hand side does not evaluate to a numeric value, then <code>ITERATE</code> can create huge symbolic expressions!
It is highly recommended to set the maximum number of iterations to a very low value when testing new expressions. If for some reason the expression on the right-hand side does not evaluate to a numeric value, then <code>ITERATE</code> can create huge symbolic expressions!


The second form of <code>ITERATE</code> iterates a list of equations that may depend on one another. The result is a vector. ITERATE sets the values of the variables on the left-hand side of the equations, so they can be accessed later with a [[VAL]] statement.
The second form of <code>ITERATE</code> iterates a list of equations that may depend on one another. The result is a vector. If you want to assign this result to the corresponding variables, assign it to a column vector.
|
|
3=
3=
<code>EXDEF ITERATE(x = cos(x), 100, 0.01, 100)</code> will start iterating with <code>x=100</code>. The next value of <code>x</code> will be <code>sqrt(100)</code>.  The result of the iteration will be approximately 0.74, since that is the solution of the equation <code>cos(x) - x = 0</code>
<code>EXDEF ITERATE(x = cos(x), 100, 0.01, 100)</code> will start iterating with <code>x=100</code>. The next value of <code>x</code> will be <code>sqrt(100)</code>.  The result of the iteration will be approximately 0.74, since that is the solution of the equation <code>cos(x) - x = 0</code>


<code>EQDEF v = ITERATE(x = cos(y);y = cos(x), 1;1, 0.01;0.01, 100)</code> boils down to finding values of <code>x</code> and <code>y</code> where <code>x - cos y = 0</code> and <code>y - cos(x) = 0</code>, that is <code>x/y = cos y/cos x</code>. The resulting value e.g. for <code>x</code> can be accessed as <code>VAL(v[1])</code> or directly with <code>VAL(x)</code>.
<code>EQDEF (stack{x#y}) = ITERATE(x = cos(y);y = cos(x), 1;1, 0.01;0.01, 100)</code> boils down to finding values of <code>x</code> and <code>y</code> where <code>x - cos y = 0</code> and <code>y - cos(x) = 0</code>, that is <code>x/y = cos y/cos x</code>. The resulting value e.g. for <code>x</code> can be accessed with <code>VAL(x)</code>.
|4=
|4=
}}
}}
[[Category:Manipulation]]
[[Category:Manipulation]]

Revision as of 16:31, 1 November 2017

Syntax

ITERATE ( equation, expression, expression, integer )

ITERATE (equation list, expression list, expression list, integer )

Implemented in iMath since version 2.2.0 or earlier.

Explanation

Iterate an equation of the form symbol = expression until it converges, that is, the difference between two consecutive values of the variable is less than the limit given as the third parameter. In every iteration step, the value of the variable found in the previous step is inserted into the expression on the right-hand side.

The last parameter gives the maximum number of iterations, in case there is no convergence.

It is highly recommended to set the maximum number of iterations to a very low value when testing new expressions. If for some reason the expression on the right-hand side does not evaluate to a numeric value, then ITERATE can create huge symbolic expressions!

The second form of ITERATE iterates a list of equations that may depend on one another. The result is a vector. If you want to assign this result to the corresponding variables, assign it to a column vector.

Example

EXDEF ITERATE(x = cos(x), 100, 0.01, 100) will start iterating with x=100. The next value of x will be sqrt(100). The result of the iteration will be approximately 0.74, since that is the solution of the equation cos(x) - x = 0

EQDEF (stack{x#y}) = ITERATE(x = cos(y);y = cos(x), 1;1, 0.01;0.01, 100) boils down to finding values of x and y where x - cos y = 0 and y - cos(x) = 0, that is x/y = cos y/cos x. The resulting value e.g. for x can be accessed with VAL(x).

See also