Monday, August 15, 2022

Review: Casio Nursing Calculator SP-100UNSU

Review:  Casio Nursing Calculator SP-100UNSU


It's rare, but there are nursing-based calculators that are available in the market from time to time.  Here is a review of one.


Quick Facts


Model:  SP-100USNU

Company:  Casio

Years:  2022-current

Type:  Nursing 

Batteries: CR2016

Operating Modes:  Chain

Number of Registers: 1

Display:  10 digits, with prompts

Cost:  $39.99 USD


The calculator that I ordered came in an ecology-friendly package, with the calculator wrapped in a bubble wrap pocket.  Unfortunately, it does not have a hard sliding case or the calculator being in a wallet.


The calculator casing has a nice silver finish with white keys.







A Calculator for the Nursing and Pharmacy Industries


The SP-100USNU is built for the nursing and pharmacy industries.  Five of the keys deal with six calculations, which each of the top keys serving as a toggle.  What is great about the SP-100USNU is that the calculator gives prompts and menus as necessary.  The display is crisp and clean.  


[ BMI ]:   Body Mass Index.   Two input modes:  lbs/ft/in,  kg/cm


[ Dose ]:  Does Calculation.   Solve for Ordered Dose given Desired Dose, or solve for Desired Dose given Ordered Dose.  Doses are in mL, with amount of the medicine (per pill, capsule, gummy, etc.) in mg.


[ BSA ]:  Body Surface Area approximation in square meters.  Two input modes:  lbs/ft/in, kg/cm


[ eGFR ]:  Calculate the estimated glomerular filtration rate which assist in diagnosis of chronic kidney disease.   The CKD-EPI equation, which factors a person's skin color (black vs. non-black), sex (male vs. female), weight (for body surface area), creatinine secretion (mg/dL), and the person's age.  What is calculated?   CCr, Creatinine Clearance, in mL/min and eGFR, estimated glomerular filtration rate, in mL/min/1.73m^2.   The average body surface area is estimated to be 1.73 m^2.  


[ IV rate ] (date):  This key toggles between two types of calculations: IV Drip Rate and Date calculation.


IV Drip Rate:  three inputs are needed.   Volume of medicine in mL, time that the IV lasts in minutes, and drop factor in gtts/mL (typically 15 - 20 gtts/mL).  gtts stands for number of drops.  The drip rate is given in gtts/min.  


Date:  Calculate the date functions for all dates in the 21st century (January 1, 2000 to December 31, 2099).  

1.  Before:  calculate the date before the base date.  

2.  After:  calculate the date after the base date.  

3.  Period: calculate the days between dates.


The formulas are given at the back of box (expect for CCr and the date calculations) and listed in the manual (expect for date calculations).   Hence the box and the manual is a neat reference.   


Link to the manual, which has to be downloaded:  https://support.casio.com/storage/en/manual/pdf/EN/004/SP-100USNU_EN.pdf


Regular Calculator  


The SP-100USNU is also a regular four function calculator.  Unfortunately neither the percent function (%) nor the square root function (√) are present.  I would think that the nursing profession would work with percentages. We do have memory calculations (M+, M-, MRC).


Also you may need access to a conversion table (via calculator, book, internet, all of the above) to do common conversions.   I would have loved to see that present here too.


Conversion Factors


1 kg = 2.20462 lb

1 in = 2.54 cm

1 L = 1000 mL

1 hr = 60 min


During the prompts, we can execute side calculations before entering the required entry in the prompt.


Final Thoughts


I did not like the fact that that calculator does not have the % and the √ functions.  It would be nice if conversion factors were included (especially with the money).  However, the formulas included make a great specialized calculator.   


Eddie 


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. 


Sunday, August 14, 2022

TI 84 Plus CE TI-Basic and TI Nspire CX II Python: Gamma by Multiplication Recursion Property

TI 84 Plus CE TI-Basic and TI Nspire CX II Python:   Gamma by Multiplication Recursion Property


Introduction


The program calculates the gamma function for any real positive number in tenths by the multiplication recursion:


Γ(x + 1) = x * Γ(x)


For example:  


Γ(2.5)

= 1.5 * Γ(1.5)

= 1.5 * 0.5 * Γ(0.5)

≈ 1.5 * 0.5 * 1.772453851

≈ 1.329340388


Reduce x by 1 until 1 is in between 0.1 and 1. 


Gamma Values:


Γ(0.1) = 9.513507699

Γ(0.2) = 4.590843712

Γ(0.3) = 2.991568988

Γ(0.4) = 2.218159544

Γ(0.5) = 1.772453851

Γ(0.6) = 1.489192249

Γ(0.7) = 1.298055333

Γ(0.8) = 1.164229714

Γ(0.9) = 1.068628702

Γ(1) = 1


TI-84 Plus CE Program: GAMMATEN

TI-Basic


Notes:


*  To get the small L to create lists with custom names, get the character with the key strokes:  [ 2nd ] ( list ), OPS, B.  L.   In this listing, I will write L^ to symbolize the lower case L.


* L^TEN is a custom list.


Program listing:


{9.513507699, 4.590843712, 2.991568988, 

2.218159544, 1.772453851, 1.489192249,

1.298055333, 1.164229714, 1.068628702

1}→L^TEN

ClrHome

Disp "GAMMA X (NEAREST 0.1)"

Input "X≥0.1, X?",X

round(X,1)→X

fPart(X)*10→F

If F=0:10→F

1→G

While X>1

G*(X-1)→G

X-1→X

End

G*L^TEN(F)→G

Disp "EST. GAMMA: ", G


TI-NSpire Python Script:  gammaten.py


The code is defined as a function.   


def gammaten(x):

  lten=[9.513507699]

  lten.append(4.590843712)

  lten.append(2.991568988)

  lten.append(2.218159544)

  lten.append(1.772453851)

  lten.append(1.489192249)

  lten.append(1.298055333)

  lten.append(1.164229714)

  lten.append(1.068628702)

  lten.append(1)

  #print("gamma(x) to the nearest 0.1")

  x=round(x,1)

  f=round(10*(x-int(x))-1)

  g=1

  while x>1:

    x-=1

    g*=x

  g*=lten[f]

  return [g,f]


# list[-1] gets last item too

# round integers for accurate results!

# 2022-06-13 EWS


Eddie 


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. 


Saturday, August 13, 2022

Plus42 and Casio fx-9750GIII: Magnetic Flux Density of a Solenoid

Plus42 and Casio fx-9750GIII:  Magnetic Flux Density of a Solenoid


Introduction:  Ampère's Circuital Law


A solenoid is an electromagnetic coil or wire that controls a magnetic field.  The solenoid is a key part of the automobile starter.  



Constant Radius:  If the solenoid has a constant radius, the simplest case, the magnetic flux density is calculated as:


B = μ0 * N * I / L


where

μ0  = permeability in a vacuum.   More about this later.

N = number of turns

I = current in Amps

B = magnetic flux density in Telsa (T, or Wb/m^2, or kg/(A*s^2)


Various Radii:  If the radii vary in the solenoid, we can calculate the sum of the magnetic flux density per each point z_i and radius R_i.  


B_i = μ0 * I * N * R_i^2 / (2 * (R_i^2 + z_i^2)^1.5)



The μ0 Constant:  Or Is It?


The μ0 represents the permeability in a vacuum, and traditionally, it is a constant defined as:


μ0 = 4 * π * 10^-7  T * m/A  ≈ 1.25663706144 * 10^-6 T * m/A  


However, CODATA has a slightly different value assigned, here is the May 2019 value:


μ0 ≈ 1.25663706212 * 10^-6  T * m/A  


Since the traditional value is reasonably close, I am going to use it the programs presented here.



Casio fx-9750GIII Program:  SOLENOID


Option 1:  Constant Radius


Option 2:  Various Radii, the total flux is calculated


Program:


4×π×10^(-7)→U

Menu "SOLENOID","CONSTANT RADIUS",1,"DIFFERENT RADII",2

Lbl 1

"TURNS"?→N

"CURRENT (A)"?→I

"LENGTH (M)"?→L

Goto 3

Lbl 2

"TURNS"?→N

"CURRENT (A)"?→I

0→B

"NO. OF RADII"?→J

For 1→K To J

"DATA"

K⊿

"RADIUS"?→R

"LENGTH"?→Z

B+(U×I×N×R)÷(2×(R^2+Z^2)^1.5)→B

Next

Goto 3

Lbl 3

"FLUX DENSITY:"⊿

B


Plus42 (HP 27S/19B/17B) Equations:  SOLENOID


Constant Radius:


SOLE1:B=4×π×ALOG(-7)×N×I÷L


Various radii (single calculation):


SOLE2:B=(4×π×ALOG(-7)×I×N×R)÷(2×(R^2+Z^2)^1.5)


Use a register to store and sum B_i.


Examples 


Constant Radius:


N = 8000 turns

L = 0.06 m

I = 30 A


B ≈ 5.026548246 Telsa


Various radii (total):


N = 2500 turns

I = 15A


(point z, radii r)

z_1 = 0 m, r_1 = 0.6 m

z_2 = 0.5 m, r_2 = 1 m

z_3 = 0.8 m, r_3 = 0.7 m


B ≈ 0.09604006539 Telsa


Sources


"CODATA Recommended Values of the Fundamental Physical Constants:  2018"  National Institute of Standards and Technology.  United States Department of Commerce.  May 2019  https://physics.nist.gov/cuu/pdf/wall_2018.pdf   Retrieved June 7, 2022. 


"Solenoid"  Wikipedia.   Last edited April 30, 2022. https://en.wikipedia.org/wiki/Solenoid    Accessed June 1, 2022. 


Nave, Carl Rod.   "Solenoid as Magnetic Field Sources"  HyperPhysics  Georgia State University.  2016  http://hyperphysics.phy-astr.gsu.edu/hbase/magnetic/solenoid.html  Accessed June 3, 2022. 



This blog entry is dedicated to Chris B. 


Eddie 


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. 


Monday, August 8, 2022

Texas Instruments: TI-36X Pro and TI-30X Pro Mathprint

 Essentially, the Texas Instruments TI-36X Pro and the TI-30X MathPrint are functionally equivalent.  What makes the two calculators different?


*  The TI-36X Pro is sold in the United States and in lot of the world, with the TI-30X MathPrint is sold primarily from Europe.  I ordered my TI-30X Pro MathPrint from the United Kingdom.  


Product pages from Texas Instruments:


TI-36X Pro (United States and Canada)

https://education.ti.com/en/products/calculators/scientific-calculators/ti-36x-pro


TI-30X MathPrint (Denmark, in Danish):

https://education.ti.com/da/products/calculators/scientific-calculators/ti-30x-pro-mp#specifications


Australia has a TI-30XPlus MathPrint, which is styled like the TI-30X Pro MathPrint, but without calculus functions.

https://education.ti.com/en-au/products/calculators/scientific-calculators/ti-30x-plus-mp?category=overview


*  Thanks to the body of the calculator being curved, the TI-36X Pro is slightly bigger than the TI-30X Pro MathPrint. 


*  The screen on the TI-36X Pro is a curved trapezoid, while the screen of the TI-30X Pro MathPrint has is rectangular.  


*  The TI-36X Pro has a circular arrow keypad while the TI-30X Pro MathPrint has a rectangular arrow keypad.  


* The TI-30X Pro Math print has black characters, while the TI-36X Pro has blue characters.


* The font on the keys of the TI-30X Pro Math are larger than than the font on the TI-36X Pro's keys.


Here are some pictures.













Either calculator is worth buying.  You  can see my review of the TI-36X Pro from 2011 here:

P.S. I still wish the TI-36X Pro/TI-30X Pro MathPrint had an alpha key instead of one key to press multiple times to get different variables.  That is my biggest gripe. 

Eddie



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. 






Sunday, August 7, 2022

Retro Review: Retro Review Radio Shack EC-480

Retro Review:   Retro Review Radio Shack EC-480








Quick Facts


Model:  EC-480

Company:  Radio Shack

Years:  1976-1977

Type:  Scientific 

Batteries: 2 x AA, separate AC power 

Operating Modes:  Chain

Number of Registers: 1

Display:  8 digits, 1 left character for shift and error indicator


The EC-480 comes to have a brown, thin faux-leather cover.  


Pocket Sized Scientific Calculator


The EC-480 is a no-frills, lightweight, scientific calculator: just the basics.   Most likely, this would be an on today's smartphones.  The keys are plastic and thankfully the keys are responsive.   You can hear a click when the keys are pressed.  


Every of the 20 keys has a shifted function.  A smart move is the put the ON-OFF switch instead of making it a key.  


The keyboard:


C/CE; 1/X

F; cf  (Shift; Clear Shift)

EEX; conv

÷; arc  (for arcsin, arccos, arctan)

7; sin

8; cos

9; tan

×; sto 

4; e^x

5; 10^x

6; y^x

-; rcl

1; ln

2; log

3; √

+; m+

+/-; x^2

0; π

.;  (

=; )


The angle measurement used is degrees.


The conv function toggles the screen.  When a number is big or small enough to show a exponent, the conv functions shows the mantissa.  For example:


5.5.638 E 11 

× 1.2365 E 10 

= 6.8796 E 21

(conv) 6.8796387   (6.8796387 * 10^21)

(conv) 6.8796 E 21


The one thing I do not like about the EC-480 is that sometimes the 10^x function is sometimes inaccurate due to rounding error.  For example:


10^3 returns 1000

10^4 returns 10000

10^5 returns 99999.999

10^6 returns 999999.99

10^7 returns 10000000


Try 2^x * 5^x instead.  (Possible keystrokes:  2 y^x x = sto 5 y^x x * rcl =)


No Order of Operations


The EC-480 does not follow the order of operations, instead of the chain operating system.  This may be a turn off for some people.  Just to illustrate this:


4 + 5 × 6 returns 54

4 + ( 5 × 6 ) returns 34

5 × 6 + 4 returns 34


Green Display


The display has 9 characters.  The right 8 contain numbers, with the left as an indicator.   


#.#.#.#.#.#.#.#.#.


The first decimal point indicator appears when you press the blue shift key.  


The left character is a negative sign with nothing else is when the calculator is sleeping.  I like this feature to save battery.  


Source


Flow Simulation Ltd.  "Radio Shack EC-480"  calculator.org 2022.  https://www.calculator.org/calculators/Radio_Shack_EC-480.html   Retrieved June 5, 2022


Eddie


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. 


Saturday, August 6, 2022

HP 12C: Cash Back vs Credit Card Interest

HP 12C: Cash Back vs Credit Card Interest


Introduction


If you have a credit card, chances are that you have a cash back program, where the company offers you cash back rate based on qualified purchases.  Is the benefit worth it?  



HP 12C Program:  Cash Back vs. Interest


Store the following data:


PV:  current credit card balance

PMT:  qualified purchases

i% using [ g ] (12÷):  monthly credit card rate

R0 using [ STO ] 0:  cash back rate


This program assumes all purchases made qualify for the cash back rate.


Step #;  Step Key;  Key


01; 45, 14; RCL PMT

02; 45, 0;  RCL 0

03; 25; %

04; 31; R/S

05; 45, 13; RCL PV

06; 45, 14; RCL PMT

07; 40;  +

08; 45, 12; RCL i

09; 25; %

10; 31; R/S

11; 40; +

12; 43,33,00; GTO 00   (use GTO 000 on HP 12C Platinum)


Outputs:


1.  Cash back 

2.  Interest charged on the balance and purchases

3.  New balance


Examples


Example 1:


Credit card balance:  $1,000.00   

Qualified purchases:  $230.00

Credit card annual rate:  15%

Cash back rate:  5%


1000 [ PV ]

230 [ PMT ]

15 [ g ] (12÷)

5 [ STO ] 0


[ R/S ]:

11.50  [ R/S ]

15.38  [ R/S ]

1241.50


Cash back:  $11.50

Interest:  $15.38

New balance:  $1,241.50


Example 2:


Credit card balance:  $585.65   

Qualified purchases:  $176.19

Credit card annual rate:  16.79%

Cash back rate:  5%


585.65 [ PV ]

176.19 [ PMT ]

16.79 [ g ] (12÷)

5 [ STO ] 0


[ R/S ]:

8.81 [ R/S ]

10.66  [ R/S ]

772.50


Cash back:  $8.81

Interest:  $10.66

New balance:  $772.50


Investigation:  Cash Back Benefit vs. Credit Card Interest


I then wondered, is there a point where the cash back gives a better benefit than the interest charged.


Consider the equation:


cash back benefits = monthly interest charge

purchases * cash_back% = (balance + purchases) * monthly_interest%

purchases * (cash_back% - monthly_interest%) = balance * monthly_interest%

purchases * (cash_back% ÷ monthly_interest% - 1) = balance 

cash_back% ÷ monthly_interest% - 1 = balance ÷ purchases


Let the test ratio be defined as:


test ratio = cash_back% ÷ monthly_interest% - 1 


Using the data from Example 2:


test ratio = 5 ÷ (16.79 ÷ 12) - 1 ≈ 5 ÷ 1.40 - 1 ≈ 3.57 - 1 = 2.57


For the cash back and interest to be equal, the purchases must equal balance÷2.57 or $227.88.  Running the program, the cash back and interest charged is around $11.38.  


This means we will have to make a lot of qualified purchases.  Say if we spent $400.00 in purchases, the cash back is $20.00, with interest $13.79, and the balance $999.44.  


To try to do this on a continuous basis poses several problems:  we still have to pay the balance otherwise we have to buy more each month to get the greater benefit.  Also, the lower the starting balance, the lower the minimum purchase requirement.


With a credit card rate of 16.79% (monthly about 1.40%) and cash back 5%, the test ratio is (5 ÷ 1.4 - 1) is 2.57.  


A beginning balance of $200.00 will require $77.82 of qualified purchases (200 ÷ 2.57), while a beginning balance of $500.00 will require $194.55 in purchases.


Take care and have a great day,


Eddie


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. 


Friday, August 5, 2022

Python - Lambda Week: Solving Differential Equations with Runge Kutta 4th Order Method

Python - Lambda Week: Solving Differential Equations with Runge Kutta 4th Order Method


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. 


Solving Differential Equations


This following script solves the differential equation:


y' = dy/dx = f(x,y)

with initial condition y(x0) = y0


Repeat the steps for each step size h:

f1 = h * f(x0, y0)

f2 = h * f(x0 + h/2, y0 + f1/2)

f3 = h * f(x0 + h/2, y0 + f2/2)

f4 = h * f(x0 + h, y0 + f3)

x0 = x0 + h   (update x)

y0 = y0 + (f1 + 2*f2 + 2*f3 + f4)/6   (update y)


The small h is, the more accurate the calculated coordinates are.  


rk4lam.py:  Runge Kutta 4th Order Method


All answers are stored in the nested list t.  


from math import *

print("Runge Kutta 4th Order")

print("Math Module imported")

f=eval("lambda x,y:"+input("dy/dx = "))


# must call for float numbers one at a time

x0=eval(input("x0 = "))

y0=eval(input("y0 = "))

h=eval(input("h = "))


# ask for an integer

n=int(input("number of steps: "))


# set up table

t=[[x0,y0]]


# main loop

for i in range(n):

  f1=h*f(x0,y0)

  f2=h*f(x0+h/2,y0+f1/2)

  f3=h*f(x0+h/2,y0+f2/2)

  f4=h*f(x0+h,y0+f3)

  x0=x0+h

  y0=y0+(f1+2*f2+2*f3+f4)/6

  print([x0,y0])

  t.append([x0,y0])


print("Done.  Recall t for table.")


Examples


Results are rounded to five digits.  


Example 1:

dy/dx = 2*x*y + x,  y(0) = 0, h = 0.1, 5 steps

(Real solution:  y = 1/2 * (e^(x^2) - 1))


Results (which matches the exact results):

x = 0.1, y ≈ 0.00503

x = 0.2, y ≈ 0.02041

x = 0.3, y ≈ 0.04709

x = 0.4, y ≈ 0.08676

x = 0.5, y ≈ 0.14201


Example 2:

dy/dx = ln x + y, y(10) = 1

(Real Solution:  y = [∫(ln t * e^(-t) dt, t = 10 to x) + e^(-10)] * e^x


Exact Results:

x = 11, y ≈ 6.74551

x = 12, y ≈ 22.51732

x = 13, y ≈ 65.53659

x = 14, y ≈ 182.60824

x = 15, y ≈ 500.96552


Runge Kutta with h = 1, 5 steps:

x = 11, y ≈ 6.71066

x = 12, y ≈ 22.33376

x = 13, y ≈ 64.78988

x = 14, y ≈ 179.90761

x = 15, y ≈ 491.80768



Runge Kutta with h = 0.1, 50 steps:

x = 11, y ≈ 6.74551   (recall t[10])

x = 12, y ≈ 22.51728   (t[20])

x = 13, y ≈ 65.53643   (t[30])

x = 14, y ≈ 182.60766  (t[40])

x = 15, y ≈ 500.96358  (t[50])


This ends Python week for now, I hope you find this week helpful and resourceful.


Until next time,


Eddie


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. 


Thursday, August 4, 2022

Python - Lambda Week: Integration by Simpson's Rule

Python - Lambda Week: Integration by Simpson's Rule



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. 


Simpson's Rule


The Simpson's Rule estimates numeric integrals by:


∫( f(x) dx, x = a to b) ≈

(b - a) /(3 * n) * (f(a) + 4 * f1 + 2 * f2 + 4 * f3 + .... + 2 * f_n-2 + 4 * f_n-1 + f(b))


n must be an even number of partitions.  The more partitions, the higher the accuracy and the higher computation time.


integrallam.py:  Numeric Integer


from math import *


print("The math module is imported.")

print("Integra of f(x), 6 places")

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


# input parameters

a=eval(input("lower = "))

b=eval(input("upper = "))

n=int(input("even parts: "))


# checksafe, add 1 if n is odd

if n/2-int(n/2)==0:

  n=n+1


# integral calculus

s=f(a)+f(b)

w=1

# 1 to n-1

for i in range(1,n):

  w=f(a+i*(b-a)/n)

  s+=(2*w) if (i/2-int(i/2)==0) else (4*w)

s*=(b-a)/(3*n)

print("Integral: "+str(round(s,6)))


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. 

Wednesday, August 3, 2022

Python - Lambda Week: Derivatives and Newton's Method

Python - Lambda Week: Derivatives and Newton's Method



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. 


Derivative


The Five Stencil Method is used.  Due to the approximate nature, results are rounded to 5 digits.


f'(x) ≈ (-f(x+2*h) + 8*f(x+h) - 8*f(x-h) + f(x-2*h)) / (12 * h)


h is set to 0.0001 to allow for a wide range of functions and to hopefully prevent float point overflows or underflows.  You can modify h or have the user input a value if you so wish.  


derivlam.py:  Derivative Using the Five Stencil Method


# Math Calculations

#================================

from math import *

#================================


print("The math module is imported.")

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


# input x0

x=eval(input("d/dx at x0: "))

h=.0001


# derivative, 5 stencil

d=(-f(x+2*h)+8*f(x+h)-8*f(x-h)+f(x-2*h))/(12*h)

print("round to 5 decimal points")

print("d/dx = "+str(round(d,5)))


Newton's Method


The next script finds the root of f(x) (solve f(x) = 0) with a guess.  


x_n+1 = x_n - f(x_n) / f'(x_n)


The derivative is calculated using the Five Stencil Method.   


I put a limit of 100 iterations because Newton's Method is not always perfect nor this script finds solutions in the complex plane, just the real numbers.  


newtonlam.py


# Math Calculations

#================================

from math import *

#================================

print("The math module is imported.")

print("Solve f(x)=0 to 6 places")

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


# input x0

x=eval(input("Guess? "))

h=.0001


w=1

n=1

while fabs(w)>10**(-7):

  d=(-f(x+2*h)+8*f(x+h)-8*f(x-h)+f(x-2*h))/(12*h)

  w=f(x)/d

  x-=w

  n+=1

  if n>100:

    print("iterations exceeded")

    break


if n<101:

  print("x = "+str(round(x,6)))

  print("iterations used: "+str(n))



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. 


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

h=(x1-x0)/n


# calculate plot lists

x=[]

y=[]

i=x0

while i<=x1:

  x.append(i)

  y.append(f(i))

  i+=h


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

# colors are defined using tuples

colors=((0,0,0),(255,0,0),(0,128,0),(0,0,255))

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

plt.auto_window(x,y)


# plot axes

plt.color(128,128,128)

plt.axes("axes")


# plot the function

plt.color(colors[c])

plt.plot(x,y,".")

plt.show_plot()



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. 


Review: Casio Nursing Calculator SP-100UNSU

Review:  Casio Nursing Calculator SP-100UNSU It's rare, but there are nursing-based calculators that are available in the market from ti...