Tuesday, August 2, 2022

Python - Lambda Week: Plotting Functions

Python - Lambda Week: Plotting Functions

Welcome to Python Week!  This we we're going to cover calculus and the keyword lambda.

Note:  All Python scripts presented this week were created using a TI-NSpire CX II CAS.   As of June 2022, the lambda keyword is available on all calculators (in the United States) that have Python.   If you are not sure, please check your calculator manual. 

Plotting Functions

We can use the line:

f=eval("lambda x:"+input("f(x) = "))

for multiple applications.   Remember, lambda functions are not defined so that they can be used outside of the Python script it belongs to but it lambda functions are super useful!

This code is specific to the Texas Instruments calculators (TI-Nspire CX II (CAS), TI-84 Plus CE Python, TI-83 CE Premium Python Edition, but NOT the TI-82 Advanced Python).    For other calculators, HP Prime, Casio fx-CG 50, Casio fx-9750GIII/9860GIII, Numworks, or computer Python, apply similar language. 

plotlam.py:  Plotting with Lambda

from math import *

import ti_plotlib as plt

# this is for the TI calcs

# other calculators will use their own plot syntax

print("The math module is imported.")

# input defaults to string

# use the plus sign to combine strings

f=eval("lambda x:"+input("f(x) = "))

# set up parameters

x0=eval(input("x min = "))

x1=eval(input("x max = "))

# we want n to be an integer

n=int(input("number of points = "))

# calculate step size


# calculate plot lists




while i<=x1:




# choose color (not for Casio fx-9750/9850GIII)

# colors are defined using tuples


print("0: black \n1: red \n2: green \n3: blue")

c=int(input("Enter a color code: "))

# plot f(x)

# auto setup to x and y lists


# plot axes



# plot the function




All original content copyright, © 2011-2022.  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. 

Casio fx-CG50 and Swiss Micros DM32: HP 16C’s Bit Summation

  Casio fx-CG50 and Swiss Micros DM32: HP 16C’s Bit Summation The HP 16C’s #B Function The #B function is the HP 16C’s number of...