Showing posts with label power. Show all posts
Showing posts with label power. Show all posts

Wednesday, March 23, 2022

March Calculus Madness Sweet Sixteen - Day 8: ∫ ln^2 x dx and ∫ ln^3 x dx

 ------------


Welcome to March Calculus Madness!


------------


Integration by parts to the rescue!


∫ ln^2 x dx


u = ln^2 x,   dv = dx

du = 2 * ln * 1/x dx,   v = x


∫ ln^2 x dx

= x * ln^2 x - ∫ 2 * ln x * 1/x * x dx

= x * ln^2 x - ∫ 2 * ln x dx


u = ln x, dv = 2 dx

du = 1/x dx, v = 2 * x


= x * ln^2 x - (2 * x * ln x - ∫ 1/x * 2 * x dx)

= x * ln^2 x - (2 * x * ln x - ∫ 2 dx)

= x * ln^2 x - 2 * x * ln x + ∫ 2 dx

= x * ln^2 x - 2 * x * ln x + 2 * x + C


∫ ln^3 x dx


u = ln^3 x dx, dv = dx

du = 3 * ln^2 x dx, v = x


= x * ln^3 x - ∫3 * ln^2 x * 1/x * x dx

= x * ln^3 x - 3 * ∫ ln^2 x dx

= x * ln^3 x - 3 * (x * ln^2 x - 2 * x * ln x + 2 * x + C)

(see the above)

=  x * ln^3 x - 3 * x * ln^2 x + 6 * x * ln x - 6 * x + D   

(where D = 3 * C, C and D are constants)


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, March 13, 2022

Casio fx-CG 50: Parametric Regression

Casio fx-CG 50:  Parametric Regression


Introduction


The program PARFIT2 attempts to pair data (x,y) using a pair of parametric equations [ x(t), y(t) ].   Each list of data will have its own curve.   


x(t), 1 ≤ t ≤ n

y(t), 1 ≤ t ≤ n

n = number of data points


Each point is assigned at t-value, which the program does automatically:

t = 1 refers to (x1, y1) → (t1, x1), (t1, y1)

t = 2 refers to (x2, y2) → (t2, x2), (t2, y2)

t = 3 refers to (x3, y3) → (t3, x3), (t3, y3)

and so on.


The program offers four regression types:


1.  Linear:  a + b*t

2.  Logarithm:  a + b*ln t

3.  Exponential:  a * b^t

4.  Power:  a * t^b


Variables used:


A = intercept for x(t)

B = slope for x(t)

R = correlation for x(t)


C = intercept for y(t)

D = slope for y(t)

S = correlation for y(t)


This allows for greater curve fitting control, which can accounts for different growth of the x data and y data, separately.


The program ends with a graph of the calculated parametric equation.  


Casio fx-CG 50 Program: PARTFIT


ClrText

Locate 1,1,"PARAMETRIC"

Locate 1,2,"FIT - 2022"

Locate 1,3,"EWS"

For 1→I To 750: Next

ParamType

ClrText

"X DATA"?→List 1

"Y DATA"?→List 2

Seq(x,x,1,Dim List 1, 1)→List 3


Menu "X=","A+BT",1,"A+Bln T",2,"A×B^T",3,"A×T^B",4

Lbl 1

LinearReg(a+bx) List 3, List 1

a→A: b→B: r→R

"A+BT"→Xt1

Goto 5

Lbl 2

LogReg List 3, List 1

a→A: b→B: r→R

"A+B×ln T"→Xt1

Goto 5

Lbl 3

ExpReg(a∙b^x) List 3, List 1

a→A: b→B: r→R

"A+B^T"→Xt1

Goto 5

Lbl 4

PowerReg List 3, List 1

a→A: b→B: r→R

"A+T^B"→Xt1

Goto 5

Lbl 5

"A, B, CORR=" ◢

[ [ A ] [ B ] [ R ] ] ◢


Menu "Y=","C+DT",A,"C+Dln T",B,"C×D^T",C,"C×T^D",D

Lbl A

LinearReg(a+bx) List 2, List 1

a→C: b→D: r→S

"C+DT"→Yt1

Goto E

Lbl B

LogReg List 2, List 1

a→C: b→D: r→S

"C+D×ln T"→Yt1

Goto E

Lbl C

ExpReg(a∙b^x) List 3, List 1

a→C: b→D: r→S

"C+D^T"→Yt1

Goto E

Lbl D

PowerReg List 3, List 1

a→C: b→D: r→S

"C+T^D"→Yt1

Goto E

Lbl E

"C, D, CORR=" ◢

[ [ C ] [ D ] [ S ] ] ◢


DrawGraph

ZoomAuto


Download the program here:  https://drive.google.com/file/d/1UVEHNZ7WILv3rSAgXy0_5kQ1lBPGEvKc/view?usp=sharing


Examples


Example 1:

(x,y):

(100.0, 10.0)

(101.3, 20.0)

(103.0, 31.7)

(104.3, 42.9)

(105.6, 54.2)

(107.0, 65.6)

(110.0, 77.0)


Fit x to linear and y to exponential.


Results:  

x(t) = 98.17142857 + 1.571428571*t,  corr = 0.9904886791

y(t) = 9.829695698 * 1.308085656^t, corr = 0.9639002639





Example 2:

(x,y):

(5.0, 0.41)

(2.9, 0.30)

(1.7, 0.20)

(0.9, 0.18)

(0.1, 0.12)


Fit x to logarithmic, y to power.


Results:  

x(t) = 5.002357022 - 3.010299732 * ln t, corr = -0.9997066364

y(t) = 0.4487684406* t^-0.7312889362,  corr = -0.9684707132




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, June 6, 2020

HP 42S/DM42/Free42: X-Ray Spectrometric Calculations

HP 42S/DM42/Free42:   X-Ray Spectrometric Calculations

Introduction

The program XRAY contains a menu of several calculations involving flat crystal spectronomers, which include:

[ >EW ]:  Energy wavelength conversion, where E * λ = 12.39852.  E = energy and λ = wavelength

[ →N ]:  Store n, where n is the nth crystal.   You can calculate for any crystal and have any number of crystals for this program.

[ANGLE]:  Calculates the double diffraction angle, in degrees, of any crystal given n, E, and λ by using the Bragg Equation:

θ = 2 * asin( (12.39852 * n) / (E * d) )

where d = the spacing of the crystal planes

You will be prompted for E and d each time.

[E KEV]:  Uses the Bragg Equation to calculate energy (E), given n, d, and θ.  You will be prompted for d and θ each time.

[ENRGY]:  Calculates the energy resolving power (δ) at an X-ray given its line energy (E), double refraction angle (θ), and angular divergence of the collimator (δ). 

ENERGY  = (E * 1000 * δ° * π / 180) / tan θ

Enter δ in degrees. 


HP 42S/DM42/Free42 Program: XRAY

This program is based on the HP 11C/HP 15C program as published by Török (see source)

00 { 241-Byte Prgm }
01▸LBL "XRAY"
02 DEG
03▸LBL 00
04 ">EW"
05 KEY 1 GTO 01
06 "→N"
07 KEY 2 GTO 02
08 "ANGLE"
09 KEY 3 GTO 03
10 "E KEV"
11 KEY 4 GTO 04
12 "ENRGY"
13 KEY 5 GTO 05
14 "EXIT"
15 KEY 6 GTO 06
16 MENU
17▸LBL 07
18 STOP
19 GTO 07
20▸LBL 01
21 EXITALL
22 1/X
23 12.39852
24 ×
25 STOP
26 GTO 00
27▸LBL 02
28 EXITALL
29 STO 01
30 GTO 00
31▸LBL 03
32 EXITALL
33 12.39852
34 RCL× 01
35 "E?"
36 PROMPT
37 ÷
38 "2d?"
39 PROMPT
40 ÷
41 ASIN
42 2
43 ×
44 "DBL ANGLE="
45 AVIEW
46 STOP
47 GTO 00
48▸LBL 04
49 EXITALL
50 12.39852
51 RCL× 01
52 "2d?"
53 PROMPT
54 ÷
55 "DBL ANGLE?"
56 PROMPT
57 2
58 ÷
59 SIN
60 1/X
61 ×
62 "E="
63 AVIEW
64 STOP
65 GTO 00
66▸LBL 05
67 EXITALL
68 "DBL ANGLE?"
69 PROMPT
70 2
71 ÷
72 TAN
73 1/X
74 "DELTA?"
75 PROMPT
76 →RAD
77 ×
78 "E?"
79 PROMPT
80 ×
81 1ᴇ3
82 ×
83 "ENERGY="
84 AVIEW
85 STOP
86 GTO 00
87▸LBL 06
88 CLMENU
89 EXITALL
90 .END.

You can download this program here:  https://drive.google.com/open?id=1k12l9Un9LgtrdC3139jS3SGYjNF30Qni

Note N is stored in Register R01.  Every other memory register can be used.

Example 

For a two-crystal spectrometer with properties:

Crystal 1 (n = 1):  6.285 Å (angstrom)  (d)
Crystal 2 (n = 2):  7.285 Å

Angular divergence:  0.31°   (δ)

An M_α  wave with wavelength 3.415 Å enters the system.  Find the energy of this M_α wave and the double refraction angle for each crystal.  Also was the energy-resolving power of each of the crystals.

 [ XEQ ] (XRAY)

3.415 ( >EN )     Result:  E = 3.63061 keV  (store this in R00)
[STO] 00

1st Crystal

[ R/S ] 
1 ( →N ) (ANGL)
"E?"  [RCL] 00 [R/S]
"2d?"  6.285 [R/S]

Result:  DBL ANGLE = 65.82494

(ENRGY)
"DBL ANGLE?" [ R/S ] (since θ is still on the X stack)
"DELTA?"  0.31 [STO] 02 [R/S]
"E?"  [RCL] 00 [R/S]

Result:  ENERGY= 30.34969 eV

2nd Crystal

[ R/S ] 
2 ( →N ) (ANGL)
"E?"  [RCL] 00 [R/S]
"2d?"  7.285 [R/S]

Result:  DBL ANGLE = 139.28586

(ENRGY)
"DBL ANGLE?" [ R/S ] (since θ is still on the X stack)
"DELTA?"  [RCL] 02 [R/S]
"E?"  [RCL] 00 [R/S]

Result:  ENERGY= 7.28859eV

Source:

Török, I. (1990), Line identification and other simple wavelength‐dispersive x‐ray spectrometric calculations using a pocket calculator. X‐Ray Spectrom., 19: 159-161. doi:10.1002/xrs.1300190314

Eddie

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

Retro Review: TI-30 (1976)

Retro Review:  TI-30 (1976) 

One more quick blog posts before I head off into surgery this week.






Quick Facts

Model:  TI-30
Company:  Texas Instruments
Type:  Scientific
Years:  1976-1982
Display:  8 digits, 5 digits with 2 digit 10^xx in scientific notation, red LED lights
Batteries:  Battery, 9 V
Original Retail Price:  $24.95
Logic:  AOS (Algebraic)

History

The TI-30 is one of the first scientific calculators to cost less than $50.00 retail, making one of the first scientific calculators to be sold to a wide audience.

The TI-30 model name is carried to present day, with the latest incarnation being the TI-30xa with a gray keyboard and wide digit display.

TI-30 from 1976 (left), TI-30Xa from 2015 (right)
Features

The first TI-30 is a simple, basic scientific calculator.  It's features include:

*  Trigonometric functions and inverse
*  Logarithmic functions and inverse
*  Powers and Roots
*  Parenthesis
*  One memory register with sum and exchange commands
*  Arithmetic, percent, reciprocal

There is a DRG key where it cycles through Degrees mode, Radians mode (indicator of I), and Gradians mode (indicator of II).

Buyers had an option of purchasing one of three carrying pouches to carry the TI-30.  The one I purchased on eBay had a denim carrying pouch and it's really nice!

The display had a few indicators which was pretty advance for its time:

When a calculation is in progress, the right-most digit displays a "twirling eight".

If an error occurs, the word "Error." is spelled out.

If the calculator is left on for a few seconds, it goes into a screen saver mode.  The screen saver has a decimal point scrolling across the screen left to right.  This is designed to save battery usage.

The TI-30 also had a power adapter, I would imagine that those would be hard to find today. 

Keyboard

I am very pleased with the keyboard:  the keys are well maintained.  The keys are easy to press.  The LED screen is clear and easy to read.  The keys are responsive, don't just try to be a speed typist and everything will be fine.  The calculator is nice and lightweight.

The only thing I had a hard time with was trying to attach the 9-V battery and closing the case.

Verdict

I'd say yes; if you are a calculator collector, it is worth collecting, even if it is only historic value.  It also doesn't cost too much, I paid $17 for mine. 

Routine Goodies

Absolute Value:  | n |
n  [ x^2 ] [ √x ]

Sign:  sgn(n) = -1 for negative, 1 for positive (does not work for n = 0)
n [ STO ] [ * ] [ x^2 ] [ √x ] [ ÷ ] [ RCL ] [ = ]

Modulus:  n mod m  with n > m, n > 0, m > 0.
n [ ÷ ] m [ STO ] [ = ] [ - ] (integer part of the result) [ = ] [ * ] [ RCL ] [ = ]

Convert to Scientific Notation:
[ * ] 1 [ EE ] [ = ]

Convert to Floating Numbers:
[ * ] 1 [ INV ] [ EE ] [ = ]

The next blog post will be on March 7, 2020.  Take care!

Eddie

All original content copyright, © 2011-2020.  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, September 28, 2019

fx-260 Solar Algorithms Part I

fx-260 Solar Algorithms Part I

All results are shown to screen accuracy. 

Sphere:  Surface Area and Volume

With the radius r,
the surface area is S = 4 * π * r^2
the volume area is V = 4/3 * π * r^3

Algorithm:
r  [SHIFT] (Min) [ x² ] [ × ] [EXP](π) [ × ] 4 [ = ]    // surface area is displayed
[ × ] [ MR ] [ ÷ ] 3 [ = ]   // area is displayed

M = r

Example:
Input:
r = 3.86

Results:
3.86  [SHIFT] (Min) [ x² ] [ × ] [EXP](π) [ × ] 4 [ = ]   
Surface Area = 187.2338956

[ × ] [ MR ] [ ÷ ] 3 [ = ] 
Volume = 204.9076123

Monthly Payment of a Mortgage or Auto Loan

Input:
A = amount of the mortgage/loan
I = annual interest rate
N = number of months

The monthly payment can be found by:
PMT = ( 1 - (1 + I/1200)^-N) / (I/1200)

Algorithm:
I [ ÷ ] 1200 [ = ] [SHIFT] (Min)   // stores I/1200 into M
1 [ - ] [ ( ] 1 [ + ] [ MR ] [ ) ] [ x^y ] N [ +/- ] [ = ]
[SHIFT] (1/x) [ × ] [ MR ] [ × ] A [ = ]     // monthly payment

Example:
Input: 
I = 4  (4%)
N = 360
A = 85000

Result:
4 [ ÷ ] 1200 [ = ] [SHIFT] (Min)   // stores I/1200 into M
1 [ - ] [ ( ] 1 [ + ] [ MR ] [ ) ] [ x^y ] 360 [ +/- ] [ = ]
[SHIFT] (1/x) [ × ] [ MR ] [ × ] 85000 [ = ]     // monthly payment

PMT = 405.8030014   ($405.80)
(I/1200 = M = 3.333333333E-03)

Electromagnetic Field Strength 

Given the EIRP (effective isotropic radiated power) of a microwave (in Watts), we can calculate the following:

Power Flux Density: 
S = EIRP / (4 * π * d^2)   (W/m^2,  d = distance from the wave source in meters)

Electric Field:
E = √(30 * EIRP) /  d   (W/m)

Magnetic Field:
H = √(EIRP / (480 * π^2 * d^2) )  (A/m)

Algorithm:

Calculating Power Flux: 
EIRP [ ÷ ] [ ( ] 4 [ × ] [EXP](π) [ × ]  d [ x² ] [ ) ] [ = ]

Calculating Electric Field: 
[ ( ] EIRP [ × ] 30 [ ) ] [SHIFT] (√) [ ÷ ] 0.5 [ = ]

Calculating Magnetic Field:
[ ( ] EIRP [ ÷ ] [ ( ] 480 [ × ] [EXP](π) [ x² ] [ × ] d [ x² ] [ ) ] [ ) ] [ √ ] [ = ]

Example:
Input:
EIRP = 1800 W
d =  0.5 m   (distance)

Results:

Calculating Power Flux: 
1800 [ ÷ ] [ ( ] 4 [ × ] [EXP](π) [ × ]  0.5 [ x² ] [ ) ] [ = ]
Power Flux: 572.9577951 W/m^2

Calculating Electric Field: 
[ ( ] 1800 [ × ] 30 [ ) ] [SHIFT] (√) [ ÷ ] 0.5 [ = ]
Electric Field: 464.7580015 W/m

Calculating Magnetic Field:
[ ( ] 1800 [ ÷ ] [ ( ] 480 [ × ] [EXP](π) [ x² ] [ × ] 0.5  [ x² ] [ ) ] [ ) ] [ √ ] [ = ]
Magnetic Field: 1.232808888 A/m

Source:  Barue, Gerardo.  Microwave Engineering: Land & Space Radiocommunications John Wiley & Sons, Inc.  Hoboken, NJ  ISBN 978-0-470-08966-5 2008

Slope and Intercept with Two Points

Given two points of a line (x1, y1) and (x2, y2) we can find the slope (a) and y-intercept (b) of the general linear equation y = a*x + b.

The trick is to use the rectangular to polar conversion to find the slope:
θ = atan((y2 - y1)/(x2 -x1))
tan θ = (y2 - y1)/(x2 -x1) = slope = a

Once the slope is found, we can solve for the y-intercept:
y = a*x + b
b = y - a*x

Algorithm:
[ ( ] x1 [ - ] x2 [ ) ] [SHIFT] (R→P) [ ( ] y1 [ - ] y2 [ ) ] [ = ] [SHIFT] (X<>Y) [ tan ]
// slope is displayed

[ × ] x1* [ +/- ] [ + ] y1* [ = ]
// intercept is displayed

*x2 and y2 can be used instead

Example:
(x1, y1) = (8, 5.5)
(x2, y2) = (4, 9.5)

Result:
[ ( ] 8 [ - ] 4 [ ) ] [SHIFT] (R→P) [ ( ] 5.5 [ - ] 9.5 [ ) ] [ = ] [SHIFT] (X<>Y) [ tan ]

Slope: -1

[ × ] 8 [ +/- ] [ + ] 5.5 [ = ]

Slope: 13.5


Tomorrow will be Part II. 

Eddie

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

HP 32SII and TI-66: Curve Fitting

HP 32SII and TI-66:  Curve Fitting

Introduction

The curve fitting program uses the linear regression module to determine the parameters b ("intercept") and m ("slope") in non-linear curves using following transformations:

Logarithmic Regression:  y = b + m * ln x
Transformations:  ( ln x, y, b, m )

Inverse Regression:  y = b + m / x
Transformations:  ( 1/x, y, b, m )

Exponential Regression:  y = b * e^(m * x)
Transformation:  ( x, ln y, e^b, m )

Power Regression:  y = b * x^m
Transformation:  ( ln x, ln y, e^b, m )

Geometric (Exponent) Regression:  y = b * m^x
Transformation:  ( x, ln y, e^b, e^m )

Simple Logistic Regression:  y = 1 / (b + m * e^(-x))
Transformation:  ( e^(-x), 1/y, b, m )

HP 32SII Program:  Curve Fitting

Note:
1.  This can be adapted into the HP 35S under one label.  Just take note of the where the label points are.
2.  The total amount of bytes used is 90.
3.  Flags 1 and 2 are used.  If flag 1 is set, e^m is calculated as slope.  If flag 2 is set, e^b is calculated as intercept.

Program:
// Initialize - LBL X
LBL X
CF 1
CF 2
CLΣ
0
RTN

// Calculation - LBL Y
LBL Y

FS? 2
e^x
STO B
VIEW B
m
FS? 1
e^x
STO M
VIEW M

STO R
VIEW R
RTN

// Logarithmic Regression - LBL L
LBL L
LN 
R/S
GTO L

// Inverse Regression - LBL I
LBL I
1/x
R/S
GTO I

// Exponential Regression - LBL E
LBL E
SF 2
x<>y
LN 
x<>y
R/S
GTO E

// Power Regression - LBL P
LBL P
SF 2
LN 
x<>y
LN 
x<>y
R/S
GTO P

// Geometric/Exponent Regression - LBL G
LBL G
SF 1
SF 2
x<>y
LN
x<>y
R/S 
GTO G

// Simple Logistic Regression - LBL S
LBL S
+/-
e^x
x<>y
1/x 
x<>y
STOP 
GTO S

Instructions:
1.  Clear the statistics data and flags by pressing [XEQ] X.
2.  Enter data points, run the proper label, and press [ Σ+ ] or [ Σ- ].

For example, for Logarithmic fit:
y_data [ENTER] x_data [XEQ] L [ Σ+ ]

Subsequent Data:
y_data [ENTER] x_data [R/S] [ Σ+ ]

This scheme allows for undoing data:
y_data [ENTER] x_data [XEQ] L [ Σ- ]

3.  Calculate intercept (B), slope (M), and correlation (R), press [XEQ] Y.

TI-66 Program:  Curve Fitting

Notes:
1.  This program should be able to entered on a TI-58, TI-58C, or TI-59.  At the time of the posting, I have not done it, so I don't have the key codes.
2.  94 steps are used.  [INV] [SBR] is merged into the RTN step.
3.  Flags 1 and 2 are used.  If flag 1 is set, e^m is calculated as slope.  If flag 2 is set, e^b is calculated as intercept.

Program:
// Initialize - key [ A ]
000 LBL
001 A
002 INV
003 ST.F
004 01
005 INV
006 ST.F
007 02
008 CSR
009 0
010 RTN

// Calculation - key [ A' ]
011 LBL
012 A'
013 OP
014 12
015 INV
016 IF.F
017 02
018 (   // left parenthesis
019 INV
020 LN X
021 LBL
022 (  // left parenthesis
023 STO
024 08
025 R/S
026 X<>T
027 INV
028 IF.F
029 01
030 )  // right parenthesis
031 INV
032 LN X
033 LBL
034 )  // right parenthesis
035 STO 
036 07
037 R/S
038 OP
039 13
040 STO
041 09
042 RTN

// Logarithmic Regression - key [ B ]
043 LBL
044 B
045 LN X
046 X<>T
047 R/S
048 RTN

// Inverse Regression - key [ C ]
049 LBL 
050 C
051 1/X
052 X<>T
053 R/S
054 RTN

// Exponential Regression - [ D ]
055 LBL 
056 D
057 ST.F
058 02
059 X<>T
060 R/S
061 LN X
062 R/S
063 RTN

// Power Regression - [ B' ]
064 LBL
065 B'
066 ST.F
067 02
068 LN X
069 X<>T
070 R/S
071 LN X
072 R/S
073 RTN

// Geometric/Exponent Regression - [ C' ]
074 LBL
075 C'
076 ST.F
077 01
078 ST.F
079 02
080 X<>T
081 R/S
082 LN X
083 R/S
084 RTN

// Simple Logistic Regression - [ D' ]
085 LBL
086 D'
087 +/-
088 INV
089 LN X
090 X<>T
091 R/S
092 1/X
093 R/S
094 RTN

Instructions:
1.  Clear the statistics data and flags by pressing [  ].
2.  Enter data points: enter x, run the proper label, enter y, press [R/S] and press [2nd] ( Σ+ ) or [INV] [2nd] ( Σ+ )  (for  Σ- ).

For example, for Logarithmic fit:
x_data [ B ] y_data [R/S]  [2nd] (Σ+)

This scheme allows for undoing data:
x_data [B] y_data [R/S] [INV] [2nd] (Σ+)

3.  Calculate intercept (B), slope (M), and correlation (R), press [2nd] [ A' ].

Examples

All results are rounded.

Example 1: Logarithmic Regression
Data (x,y):
(33.8, 102.4)
(34.6, 103.8)
(36.1, 105.1)
(37.8, 106.9)

Results:
B:  -33.4580
M:  38.6498
R:  0.9941

y ≈ -33.4580 + 38.6498 ln x

Example 2:  Inverse Regression
Data (x,y):
(100, 425)
(105, 429)
(110, 444)
(115, 480)

B:  823.80396
M:  -40664.72143
R:  -0.91195

y ≈ 823.80396 - 40664.72143/x

Example 3: Simple Logistic Regression
Data (x,y):
(1, 11)
(1.3, 9.615)
(1.6, 8.75)
(1.9, 8.158)
(2.6, 7.308)

B: 0.14675
M: -0.15487
R:  -0.99733

y ≈ 1 / (0.14675 - 0.15487*e^(-x))


Eddie

All original content copyright, © 2011-2019.  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, May 19, 2018

Calculus/TI-84 Plus CE: Derivatives of kth Order


Calculus/TI-84 Plus CE:  Derivatives of Kth Order

Introduction

Can we find a general formula for a derivative of nth order?

d^n/dx^n f(x) = ?

The Power Function x^n

From calculus, we find that:

f(x) = x^n

d/dx x^n = n * x^(n - 1)

d^2/dx^2 x^n = n * (n – 1) * x^(n – 2)

d^3/dx^3 x^n = n * (n – 1) * (n – 2) * x^(n – 3)

d^4/dx^4 x^n = n * (n – 1) * (n – 2) * (n – 3) * x^(n – 4)

Note that for order k,

d^k/dx^k x^n = (n * (n – 1) * (n – 2) * (n – 3) * … * (n – (k – 1)) ) * x^(n – k)

d^k/dx^k x^n = (n * (n-1) * (n-2) * … * 1)/((n-k) * (n-k-1) * … * 1) * x^(n – k)

d^k/dx^k x^n = n! / (n – k)! * x^(n – k)

With the gamma function property Γ(z + 1) = z!,

d^k/dx^k x^n = Γ(n + 1)/Γ(n – k + 1) * x^(n – k)

The above formula allows us to calculate the kth derivative of x^n, even when k is not an integer. 

TI-84 Plus CE Program NDERPOW

"2018-05-18 EWS"
Disp "D^K/DX^K X^N"
Input "POWER (N):",N
Input "VALUE    :",A
Input "ORDER (K):",K
If N≥K
Then
N!/(N-K)!*A^(N-K)→D
Else
0→D
End
Disp D

The program NDERPOW calculates the numerical derivative of d^k/dx^k x^n.  For this particular program, k must be an integer since non-integers are not accepted on the TI-84 Plus’ factorial function. 

The Exponential Function e^(a*x), where a is a constant

f(x) = e^(a*x)

d/dx e^(a*x) = a * e^(a*x)

d^2/dx^2 e^(a*x) = a^2 * e^(a*x)

d^3/dx^3 e^(a*x) = a^3 * e^(a*x)

d^4/dx^4 e^(a*x) = a^4 * e^(a*x)

With the order k…

d^k/dx^k e^(a*x) = a^k * e^(a*x)

Just like the last case, k does not have be an integer. 

TI-84 Plus CE Program NDEREXP

"2015-05-18 EWS"
Disp "D^K/DX^K e^(A*X)"
Input "COEFF (A):",A
Input "VALUE    :",X
Input "ORDER (K):",K
A^K*e^(A*X)→D
Disp D

The program NDEREXP calculates the numerical derivative of d^k/dx^k e^(a*x).

The Sine Function sin(a*x) and the Cosine Function cos(a*x)

We are working radian angle measure.

f(x) = sin(a*x)

d/dx sin(a*x) = a * cos(a*x)

d^2/dx^2 sin(a*x) = -a^2 * sin(a*x)

d^3/dx^3 sin(a*x) = -a^3 * cos(a*x)

d^4/dx^4 sin(a*x) = a^4 * sin(a*x)

Notice a pattern, alternating between sin and cos.  To the kth order (k is an integer),

d^k/dx^k sin(a*x) =

(-1)^int(k/2) * a^k * cos(a*x), when k is odd

(-1)^int(k/2) * a^k * sin(a*x), when k is even

If we put the piecewise function into one statement:

d^k/dx^k sin(a*x) = (-1)^int(k/2) * a^k * ( 2*frac(k/2)*cos(a*x) + 2*frac((k+1)/2)*sin(a*x) )

Note that:

2 * frac(k/2) = 1 for all odd integers k, 0 for all even integers k

Likewise, 2 * frac((k + 1)/2) = 0 for all odd integers k, 1 for all even integers k

And, (-1)^int(k/2) produces a pattern of 1, -1, -1, 1, 1, -1, -1, 1, 1, -1, …

TI-84 Plus CE Program NDERSIN

"2018-05-19 EWS"
Disp "D^K/DX^K sin(A*X)"
Radian
Input "COEFF (A):",A
Input "VALUE    :",X
Input "ORDER (K):",K
(­1)^iPart(K/2)*A^K*(2*fPart(K/2)*cos(A*X)+2*fPart((K+1)/2)*sin(A*X))→D
Disp D

Similarly,

f(x) = cos(a*x)

d/dx cos(a*x) = -a * sin(a*x)

d^2/dx^2 cos(a*x) = -a^2 * cos(a*x)

d^3/dx^3 cos(a*x) = a^3 * sin(a*x)

d^4/dx^4 cos(a*x) = a^4 * cos(a*x)

Likewise:

Notice a pattern, alternating between sin and cos.  To the kth order (k is an integer),

d^k/dx^k sin(a*x) =

(-1)^int(k/2 + 1/2) * a^k * sin(a*x), when k is odd

(-1)^int(k/2 + 1/2) * a^k * cos(a*x), when k is even

If we put the piecewise function into one statement:

d^k/dx^k cos(a*x) = (-1)^int(k/2 + 1/2) * a^k * ( 2*frac(k/2)*sin(a*x) + 2*frac((k+1)/2)*cos(a*x) )

TI-84 Plus CE Program NDERCOS

"2018-05-19 EWS"
Disp "D^K/DX^K cos(A*X)"
Radian
Input "COEFF (A):",A
Input "VALUE    :",X
Input "ORDER (K):",K
(­1)^iPart((K+1)/2)*A^K*(2*fPart(K/2)*sin(A*X)+2*fPart((K+1)/2)*cos(A*X))→D
Disp D

NDERSIN and NDERCOS are numeric derivatives for sine and cosine, respectively.  Note for NDERSIN and NDERCOS, the calculator is set to Radian mode, and K (order) should be an integer. 

Eddie

All original content copyright, © 2011-2018.  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.  Please contact the author if you have questions.

Saturday, November 4, 2017

HP Prime: Best Regression Fit

HP Prime:  Best Regression Fit

The program BESTFIT compares a set of regressions to determine a best fit.  This simulates a feature presented on the Hewlett Packard HP 48S, HP 48G, HP 49G, and HP 50g.  BESTFIT compares the correlations of the following four regression models:

1.  Linear:  y = a * x + b
2.  Logarithmic:  y = a * ln x + b
3.  Exponential:  y = b * a^x   (y = b * e^(ln a * x))
4.  Power: y = b * x^a

The output is a two element list:  a string of the best fit equation and its corresponding correlation.

HP Prime Program:  BESTFIT

EXPORT BESTFIT(L1,L2)
BEGIN
// 2017-11-02 EWS
// Simulate Best Fit
// HP 48GX,49G,50g

// initialize
LOCAL clist,m,c,v,s,n;
clist:={0,0,0,0};

// test
// correlation is linear only
// requires approx()
// linear y=a*x+b
clist[1]:=approx(correlation(L1,L2));
// log y=a*LN(x)+b
c:=approx(correlation(LN(L1),L2));
IF IM(c)==0 THEN
clist[2]:=c;
END;
// exponential y=b*e^(a*x)
c:=approx(correlation(L1,LN(L2)));
IF IM(c)==0 THEN
clist[3]:=c;
END;

// power y=b*a^x
c:=approx(correlation(LN(L1),LN(L2)));
IF IM(c)==0 THEN
clist[4]:=c;
END;

// test
// POS(L0^2,MAX(L0^2))
m:=POS(clist^2,MAX(clist^2));
c:=clist[m];

IF m==1 THEN
v:=linear_regression(L1,L2);
s:=STRING(v[2])+"+"+STRING(v[1])+
"*X";
RETURN {s,c};
END;

IF m==2 THEN
v:=logarithmic_regression(L1,L2);
s:=STRING(v[2])+"+"+STRING(v[1])+
"*LN(X)";
RETURN {s,c};
END;

IF m==3 THEN
v:=exponential_regression(L1,L2);
s:=STRING(v[2])+"*"+STRING(v[1])+
"^X";
RETURN {s,c};
END;

IF m==4 THEN
v:=power_regression(L1,L2);
s:=STRING(v[2])+"*X^"+
STRING(v[1]);
RETURN {v,s};
END;

END;

Examples – BESTFIT:

Example 1:

X
y
1.05
10.45
2.28
11.33
4.20
16.38
6.34
28.87

Result: {“7.78250037344*1.21713132288^X”, 0.981261724397}
Example 2:

X
Y
-10
82
-5
41
5
-42
10
-79

Result:  {“0.5+ -8.1*X”, -0.999801918343}


Example 3:

X
Y
10
2.278
11
2.666
12
2.931
13
3.212

Result:  {“-5.79464870365+3.51429873838*LN(X)”, 0.998295735284}

BESTFIT2:  An Extended Version

Version 2 adds the following regressions: 

5.  Inverse:  y = b + a/x
6.  Simple Logistic:  y = 1/(b + a*e^(-x))
7.  Simple Quadratic:  y = b + a*x^2
8.  Square Root:  y = √(a*x + b)

HP Prime Program:  BESTFIT2

EXPORT BESTFIT2(L1,L2)
BEGIN
// 2017-11-02 EWS
// Simulate Best Fit
// HP 48GX,49G,50g
// additional models

// initialize
LOCAL clist,m,c,v,s;
clist:={0,0,0,0,0,0,0,0};

// test
// correlation is linear only
// requires approx()

// linear y=a*x+b
clist[1]:=approx(correlation(L1,L2));

// log y=a*LN(x)+b
c:=approx(correlation(LN(L1),L2));
IF IM(c)==0 THEN
clist[2]:=c;
END;

// exponential y=b*e^(a*x)
c:=approx(correlation(L1,LN(L2)));
IF IM(c)==0 THEN
clist[3]:=c;
END;

// power y=b*a^x
c:=approx(correlation(LN(L1),LN(L2)));
IF IM(c)==0 THEN
clist[4]:=c;
END;

// inverse y=b+a/x
IF POS(L1,0)==0 THEN
clist[5]:=approx(correlation(1/L1,
L2));
END;

// simple logistic
IF POS(L2,0)==0 THEN
clist[6]:=approx(correlation(e^(−L1),
1/L2));
END;

// simple quadratic
clist[7]:=approx(correlation(L1^2,
L2));

// square root
IF ΣLIST(L2≥0)==SIZE(L2) THEN
clist[8]:=approx(correlation(L1,
L2^2));
END;



// test
// POS(L0^2,MAX(L0^2))
m:=POS(clist^2,MAX(clist^2));
c:=clist[m];

IF m==1 THEN
v:=linear_regression(L1,L2);
s:=STRING(v[2])+"+"+STRING(v[1])+
"*X";
END;

IF m==2 THEN
v:=logarithmic_regression(L1,L2);
s:=STRING(v[2])+"+"+STRING(v[1])+
"*LN(X)";
END;

IF m==3 THEN
v:=exponential_regression(L1,L2);
s:=STRING(v[2])+"*"+STRING(v[1])+
"^X";
END;

IF m==4 THEN
v:=power_regression(L1,L2);
s:=STRING(v[2])+"*X^"+
STRING(v[1]);
END;

// inverse
IF m==5 THEN
v:=linear_regression(1/L1,L2);
s:=STRING(v[2])+"+"+STRING(v[1])+
"/X";
END;

// simple logistic
IF m==6 THEN
v:=linear_regression(e^(−L1),
1/L2);
s:="1/("+STRING(v[2])+"+"+
STRING(v[1])+"*e^(−X))";
END;

// simple quadratic
IF m==7 THEN
v:=linear_regression(L1^2,L2);
s:=STRING(v[2])+"+"+STRING(v[1])+
"*X^2";
END;

// square root
IF m==8 THEN
v:=linear_regression(L1,L2^2);
s:="√("+STRING(v[2])+"+"+
STRING(v[1])+"*X)";
END;

RETURN {s,c};
END;

Examples – BESTFIT2:

Example 4:

X
y
1.05
10.45
2.28
11.33
4.20
16.38
6.34
28.87

Result:  {“9.0573970192+0.48023219108*X^2”, 0.994491728382}

Example 5:

X
y
1
8.4853
2
8.9443
4
9.7980
7
10.9546

Result: {“√(63.9995089183+8.00048914762*X”, 0.999999999759}

Example 6:

X
y
1
1
2
-0.5
3
-1
4
-1.25

Result:  {“-2+3/X”, 1}

Eddie

This blog is property of Edward Shore, 2017

Spotlight: Akron Brass FireCalc Pocket Computer

Spotlight: Akron Brass FireCalc Pocket Computer Welcome to a special Monday Edition of Eddie’s Math and Calculator blog. Thi...