Showing posts with label SUMIF. Show all posts
Showing posts with label SUMIF. Show all posts

Saturday, November 6, 2021

TI-92 Plus and TI-Nspire CX II: List Filters

TI-92 Plus and TI-Nspire CX II:  List Filters




For this particular post, I also have a TI-Nspire CX II CAS document which can be downloaded here:  https://drive.google.com/file/d/1Rm5vIWdUMg5OEyXi4VecNfuIGdiGRtan/view?usp=sharing


The functions are public and are available in the catalog.  Examples and syntax are included.  


The Filters


filters(list, criteria): filters out a list 

sumfilt(list, criteria): sum of selected elements of a list

avgfilt(list, criteria): arithmetic average of elements of a list

prdlist(list, criteria): product of selected elements of a list

dimfilt(list, criteria): returns a count of list elements that fit a criteria


This is similar to Excel functions filter, sumifs, averagefits, and countifs; there is no productifs in Excel.  


The criteria is a string, using x as a variable.  Examples:

"x<10": select elements less than 10

"x≥20": select elements greater than or equal to 20

"10<x and x<20": select elements between 10 and 20, not including 10 or 20

"10≤x and x≤20": select elements between 10 and 20, including 10 or 20


TI-92 Plus Functions: Filters


Note:  I am using the symbol [| for comment; in the program editor, select F2, option 9.  


TI-92 Plus Function:  filters


filters(list1,cr) 

Func

[| list, criteria string with x

[| EWS 2021-08-13

[| filter function

Local list2,d,i,t,x

{}→list2

dim(list1)→d

For i,1,d

expr(cr)|x=list1[i]→t

If t Then

augment(list2,{list1[i]})→list2

EndIf

EndFor

Return list2

EndFunc


TI-92 Plus Function: sumfilt


sumfilt(list1,cr) 

Func

[| list, criteria string with x

[| EWS 2021-08-14

[| sum-if filter function

Local list2,d,i,t,x

{}→list2

dim(list1)→d

For i,1,d

expr(cr)|x=list1[i]→t

If t Then

augment(list2,{list1[i]})→list2

EndIf

EndFor

Return sum(list2)

EndFunc


TI-92 Plus Function: avgfilt


avgfilt(list1,cr) 

Func

[| list, criteria string with x

[| EWS 2021-08-14

[| average-if filter function

Local list2,d,i,t,x

{}→list2

dim(list1)→d

For i,1,d

expr(cr)|x=list1[i]→t

If t Then

augment(list2,{list1[i]})→list2

EndIf

EndFor

Return sum(list2)/(dim(list2))

EndFunc


TI-92 Plus Function:  prdfilt


prdfilt(list1,cr) 

Func

[| list, criteria string with x

[| EWS 2021-08-14

[| product-if filter function

Local list2,d,i,t,x

{}→list2

dim(list1)→d

For i,1,d

expr(cr)|x=list1[i]→t

If t Then

augment(list2,{list1[i]})→list2

EndIf

EndFor

Return product(list2)

EndFunc


TI-92 Plus Function:  dimfilt


dimflt(list1,cr) 

Func

[| list, criteria string with x

[| EWS 2021-08-13

[| count-if filter function

Local list2,d,i,t,x

{}→list2

dim(list1)→d

For i,1,d

expr(cr)|x=list1[i]→t

If t Then

augment(list2,{list1[i]})→list2

EndIf

EndFor

Return dim(list2)

EndFunc


Examples:


list0 = {2,4,5,6,9,10,11,13,14,15,18}


filters(list0,"x≤10"):  {2,4,5,6,9}

filters(list0,"5≤x and x≤15"):  {5,6,9,10,11,13,14,15}


sumfilt(list0,"x≤10"):  36

sumfilt(list0,"5≤x and x≤15"):  83


avgfilt(list0,"x≤10"):  6

avgfilt(list0,"5≤x and x≤15"):  83/8


prdfilt(list0,"x≤10"):  21600

prdfilt(list0,"5≤x and x≤15"):  2700


dimfilt(list0,"x≤10"):  6

dimfilt(list0,"5≤x and x≤15"):  8


All original content copyright, © 2011-2021.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Sunday, September 5, 2021

TI-Nspire CX II and TI-84 Plus CE: COUNTIF, SUMIF, AVERAGEIF

TI-Nspire CX II and TI-84 Plus CE:  COUNTIF, SUMIF, AVERAGEIF


Introduction


Three popular spreadsheet functions are operating on elements of a list contingent of a criteria.   


Let L be a list of numerical data.


COUNTIF(L, criteria):   returns a count of all the elements that fit a criteria


SUMIF(L, criteria):  returns the sum of all the elements that fit a criteria


AVERAGEIF(L, criteria):  returns the arithmetic average of all the elements that fit a criteria


Example:


L = {0, 1, 2, 3, 4, 5, 6}


COUNTIF(L, "≥4") = 3.  

Counts all the elements of L that are greater than or equal to 4.


SUMIF(L, "≥4") = 15

Sums all the element's of L that are greater than or equal to 4. 


AVERAGEIF(L, "≥4") = 5

Returns the arithmetic average of L that are greater than or equal to 4.


Note that:


AVERAGEIF(L, criteria) = SUMIF(L, criteria) ÷ COUNTIF(L, criteria)


TI-Nspire CX II:  The functions countif and sumif


The TI-Nspire has two built in functions countif and sumif.  The averageif can easily be defined in the equation from the last section.


You can download a tns demonstration document here:  

https://drive.google.com/file/d/1XfRyHSQz92TXGmzohhej0--wLYS0yxkF/view?usp=sharing


TI-84 Plus CE Programs:  LISTIF


The program LISTIF calculates all three functions COUNTIF, SUMIF, and AVERAGEIF.  There are two custom lists that are created as a result of this program:


List A:  The input list.


List B:  The list that meets the criteria.


To get the small "L" character, press [ 2nd ], [ stat ] (LIST), B* for the small L.   The small L must be the first character of your list name.  Once created, custom lists are shown under the LIST - NAMES menu.


Although I did not test this on previous calculators, this program should work on the TI-82, TI-83 family, and all of the TI-84 Plus family.


Program listing:


Download Link:

Eddie

All original content copyright, © 2011-2021.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Earth's Radius by Latitude

Earth's Radius by Latitude Introduction: Calculating the Earth’s Radius In quick, general calculations, we assume that the...