Tuesday, May 10, 2016

HP Prime: The EXECON Command Tutorial

HP Prime:  The EXECON Command Tutorial


The EXECON Command



The EXECON creates a new list based on the elements in one or more lists by given an operation.  You can create any expression.  The list returned may or may not be the same length of the original lists.

The general syntax is:

EXECON( expression, list 1, [list 2], [list 3], …)

You can use more than one list. The expression is set in quotes.  To use the list elements, call up the ampersand (&).   Call up the ampersand symbol by pressing [ Shift ], [ 9 ] (and choose the ampersand).   Example expressions include “&1+&2” and “&1^3”. 

On this tutorial we will use EXECON for specific situations. 

Calling the EXECON Command

You can call the EXECON command from the Catalog or in the Programming editing mode by selecting (Cmds), 7 for More, 8 for EXECON (version 10077). 

For the tutorial set L1 and L2 as:

L1 = {1, 2, 3, 4, 5}
L2 = {2, 4, 6, 8, 10}

Situation 1:  Operate on each member of a list.

Your expression string will contain &1 any time you want to reference the list.  EXECON executes the function f(&1, any constants).  As a reminder, you can get the ampersand symbol by pressing [ Shift ], 9, and then selecting it from the character table.

Example 1:  Take the cube of each element of L1.
Syntax:  EXECON(“&1^3”, L1)
Results:  {1, 8, 27, 64, 125}

Example 2:  Apply the function 2*e^x – x to each element of L1.
Syntax:  EXECON(“2*e^(&1)-&1”,L1)
Results (to 5 decimal places): {4.43656, 12.77811, 37.17107, 105.19638, 291.82632}

Situation 2:  Operate a function for two lists, element by element.

Include &1 for the first list and &2 for the second list.  This is going to the resulting list:

{ f(&1(1), &2(1)),  f(&1(2), &2(2)),  f(&1(3), &2(3)), … , f(&1(n), &2(n)) }

You can extend this to three lists or more by adding &3, &4, etc… up to nine lists. 

The order of arguments are important. 

EXECON(“&1/&2”, L1, L2) returns {0.5, 0.5, 0.5, 0.5, 0.5}

EXECON(“&1/&2”, L2, L1) returns {2, 2, 2, 2, 2}

Situation 3:  Condensing a List by operating on two or more elements.

Here we are going to use one list.  To execute an operation on two consecutive elements, use &1 and &2.  Remember, we are only using one list.  In this context, &1 and &2 represent neighboring elements.  Hence:

Input:   {a1, a2, a3, a4, …. , a_n-2, a_n-1, a_n}
Output:  { f(a1, a2), f(a2, a3), f(a3, a4), … , f(a_n-2, a_n-1), f(a_n-1, a_n)}

Example:  EXECON(“&1*&2”, L1) returns {2, 6, 12, 20}

To execute an operation for elements two apart, use &1 and &3. 

Input:   {a1, a2, a3, a4, …. , a_n-2, a_n-1, a_n}
Output:  { f(a1, a3), f(a2, a4), f(a3, a5), … , f(a_n-2, a_n)}

Example:  EXECON(“&1*&3”, L1) returns {3, 8, 15}

If you want to execute an operation on three consecutive elements, use &1, &2, and &3.

Input:   {a1, a2, a3, a4, …. , a_n-2, a_n-1, a_n}
Output:  { f(a1, a2, a3),  f(a2, a3, a4), … , f(a_n-2, a_n-1, a_n) }

Example:  EXECON(“&1*&2*&3”, L1) returns {6, 24, 60}

Situation 4:  Starting at specific position of the list.  (up to 9 lists, to the start point of the 9th element)

To start at a specific element later in the list, use the syntax &mn,  the mth list, the nth element.

Example 1:

EXECON(“&13 + &2”, L1, L2) will operate on the following elements:  {3, 4, 5} from L1 (starting at the 3rd element) and {2, 4, 6} from L2.    The result will be {5, 8, 11}.

Example 2:

EXECON(“&1 * &22”, L1, L2) will operate on the following elements:  {1, 2, 3, 4} from L1 and {4, 6, 8, 10} from L2 (starting from the 2nd element).  The result is {4, 12, 24, 40}.

Please refer to the illustration below.




This is a basic demonstration of EXECON.  I hope you found this tutorial useful.   Until next time,

Eddie


This blog is property of Edward Shore, 2016.