Do - Maple Help

DocumentTools

 Do

 Calling Sequence Do(expr) Do(var=expr) Do(target=expr, refreshopt)

Parameters

 expr - algebraic ; expression to evaluate using component values var - name ; variable in which to store the retrieved value target - name ; target component to store results refreshopt - expression of the form refresh = value, where value is true or false; specifies whether or not to immediately update the document

Description

 • The Do command evaluates its argument using values retrieved from specified embedded components.
 • Optionally, the result can be stored into an embedded component
 • A naming convention is used to access component values.The expression %name refers to the component named name
 • By default, the attribute that will be queried or set is value, except for MathExpressionComponent for which the attribute that will be queried or set is expression. Alternate attributes can be specified using %name(attr)
 • After retrieving an attribute of a component, the result will be parsed and must be a valid Maple expression. To avoid parsing, refer to the component using %%name. Note that parsing of the value attribute of a MathExpressionComponent will result in an error (the expression attribute should be used instead).
 • After parsing, a type-check can be automatically applied by specifying the type using %name::type or %name(attr)::type. An error will be generated if the expression is not of the given type.
 • The result of querying component attributes can optionally be stored in a variable or in another component.
 • To store the value in a variable, use Do(myvar= ... %ComponentName ...).
 • To store the value in another component, use Do(%Comp1 = ... %Comp2 ...).
 • Note: Some embedded components, like Label, do not have a value attribute. To retrieve or set attributes on such components, an explicit attribute needs to be specified, e.g. %MyLabel(caption).
 • By default, when this command is invoked from inside the code which is executed as the action of another embedded component, the document is not updated until that code terminates.  The option refresh = true (or just refresh) can be used to force the document to update during the call to Do.

Examples

 > $\mathrm{with}\left(\mathrm{DocumentTools}\right)$

Insert a Math Expression component and two Text Area components from the Components palette.  Change the name of each component to expression, from, and to respectively by editing the Name field in the component properties.  To view and edit component properties, select a component, and then make the changes to the component properties shown in the Context Panel. Now, enter an expression into the Math Expression component and integers into the two Text Area components accordingly.

 > $\mathrm{Do}\left(\mathrm{int}\left(\mathrm{%expression},x=\mathrm{%from}::'\mathrm{integer}'..\mathrm{%to}::'\mathrm{integer}'\right)\right)$

Insert three Math Expression components called ResultField, InputField1, and InputField2.  Enter expressions into the InputFields.

 > $\mathrm{Do}\left(\mathrm{%ResultField}=2\mathrm{%InputField1}+\mathrm{%InputField2}\right)$

Insert two Math Expression components, and enter an integer into the first, called PrecisionField, and an expression which evaluates to a floating point value in the second, called Input.

 > $\mathrm{Do}\left(q=\mathrm{evalf}\left[\mathrm{%PrecisionField}::'\mathrm{integer}'\right]\left(\mathrm{%Input}\right)\right)$

Insert a Button component called MyButton, and two Text Area components, called TF and MF.  Enter numbers into both of the Text Area components.

 > $\mathrm{Do}\left(\mathrm{%MyButton}\left(\mathrm{caption}\right)=\mathrm{%TF}\left(\mathrm{value}\right)\mathrm{%MF}+1\right)$

Insert two Plot components called Plot1 and Plot2.

 > $\mathrm{Do}\left(\mathrm{%Plot1}=\mathrm{plot}\left({x}^{2},x=0..1\right)\right)$
 > $\mathrm{Do}\left(\mathrm{%Plot2}=\mathrm{%Plot1}\right)$

This example shows a math container being updated at two second intervals, using the refresh option.

 > $R≔\mathrm{Statistics}:-\mathrm{Sample}\left(\mathrm{Statistics}:-\mathrm{RandomVariable}\left(\mathrm{Normal}\left(0,1\right)\right),4\right);$$\mathbf{for}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}i\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{to}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}4\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathrm{DocumentTools}:-\mathrm{Do}\left(\mathrm{%MathContainer}=R\left[i\right],'\mathrm{refresh}'=\mathrm{true}\right);\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathrm{st}≔\mathrm{time}\left[\mathrm{real}\right]\left(\right);\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathbf{while}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathrm{time}\left[\mathrm{real}\right]\left(\right)-\mathrm{st}<2\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\left(\right)\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\phantom{\rule[-0.0ex]{2.0em}{0.0ex}}\mathbf{end}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}\phantom{\rule[-0.0ex]{0.0em}{0.0ex}}\mathbf{end}\phantom{\rule[-0.0ex]{0.3em}{0.0ex}}\mathbf{do}:$