Showing posts with label derivatives. Show all posts
Showing posts with label derivatives. Show all posts

Saturday, October 29, 2022

Plus42 Solver: Derivatives

Plus42 Solver: Derivatives 




Introduction


The Technical Applications book for the HP 27S and HP 19B (and can apply to the HP 17B outside of trigonometry) shows the numerical first and second derivative can be calculated by the formulas:


f ' (x) = (f(x+h) - f(x-h)) / (2 * h)


f ' ' (x) = (f(x + h) - 2 * f(x) + f(x + h)) / h^2 


where h is sufficiently small, like 10^-5 to 10^-12.



Legacy Formulas vs. Plus42 Formulas 


The formulas suggested by the Technical Applications Book are:


First Derivative:



Second Derivative:


Depending on the function FX, this above can turn the above into long equations.  With the ability of user functions, this allows us to use the original definitions.


FX(X): f(x) (insert f(x)


First Derivative:


F'X=(FX(X+H)-FX(X-H))÷(2×H)


Second Derivative:


F''X=(FX(X+H)-2×FX(X)+FX(X-H))÷SQ(H)


SQ:  press by the key sequence [(shift)] (x^2)


':  (ALPHA) [ ↓ ] (PUNC) [ ↓ ] ( ' )


Note:  Radians mode 



Examples 


FIX 5 mode is set.


Example 1:


f(x) = 0.5 * cos(3*x)

x = π/4


FX(X):0.5×COS(3×X)

f'(x) ≈ -1.06066

f''(x) ≈ 3.18198


Example 2:


f(x) = (x^2 + 3*x + 5) / (4*x - 1)

x = 2


FX(X):(X^2+3×X+5)÷(4×X-1)

f'(x) ≈ -0.22449

f''(x) ≈ 0.54227



Functions with Variable Constants


It is easy to expand the user function FX to include variable constants.  For example:


f(x) = -ln(cos(√(a*x)))

Calculate the value and first derivative at x = 0.11 and a = 0.46


Attach variable constants at the end of FX:


FX(X:A):-LN(COS(SQRT(A×X)))

F'X=(FX(X+H:A)-FX(X-H:A))÷(2×H)


f(x:a) ≈ 0.02552

f'(x:a) ≈ 0.23396


The user function makes the calculating numerical derivatives easier.  


Source:


Technical Applications: Step-by-Step Solutions for Your HP-27S or HP-19B Calculator Hewlett Packard.   Edition 2.  Corvallis, OR.   November 1988.  pg. 44


Have any Halloween plans?  Wishing you 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. 


Saturday, May 21, 2022

Swiss Micros DM41X and HP 41C: Numeric Derivatives

Swiss Micros DM41X and HP 41C:  Numeric Derivatives


Introduction


The program DFX calculates one of three types of derivative:


1.  Normal Derivative   (DX)

2.  Logarithmic Derivative (LN)

3.  Power Derivative (PWR)


Where:


Normal Derivative:  f'(x)


Logarithmic Derivative:  d/dx( ln f(x) ) = f'(x) / f(x)  


Power Derivative:  d/dx( f^n(x) ) = n * f^(n-1)(x) * f'(x),  n doesn't have to be an integer


where f'(x) is estimated by:


f'(x) ≈ ( f(x + h) - f(x) ) / h


Variables:  x, h


The program uses a subroutine FX, see the examples for details.  


DM41X and HP 41C Program:  DFX


Uses program FX as a subroutine as f(x).


01 LBL ^T FX

02 RCL 01

03 ^T X?

04 ARCL 01

05 PROMPT

06 STO 01

07 RCL 02

08 ^T H?

09 ARCL 02

10 PROMPT

11 STO 02

12 RCL 01

13 XEQ ^T FX

14 RCL 03

15 RCL 01

16 RCL 02

17 +

18 XEQ ^T FX

19 RCL 03

20 -

21 RCL 02

22 /

23 STO 04

24 ^T 1 DX 2 LN 3 ↑N

25 PROMPT

26 INT

27 STO 05

28 GTO IND 05


29 LBL 01

30 RCL 04 


31 LBL 02

32 RCL 04

33 RCL 03

34 / 

35 GTO 04


36 LBL 03

37 RCL 03

38 ^T N?

39 PROMPT

40 1

41  - 

42 Y↑X

43 LASTX

44 1

43 +

44 *

45 RCL 04

46 *


50 LBL 04

51 RTN



The function FX:


x is loaded in the X stack register (and on display)


01 LBL ^FX

02  execute f(x)

...

##  RTN


For DFX, do not use R01, R02, R03, R04, and R05 in FX.  


Notes:


Sequences such as:

02 RCL 01

03 ^T X?

04 ARCL 01

05 PROMPT


Puts the prompt as X? [contents of R1].   If you want the previous value, press R/S.  Otherwise enter a new value, then press R/S.


This program uses indirect goto statements.  R05 is used to hold the person's choice and uses it to direct which label is executed.


Examples


Example 1:  f(x) = x * sin x


Set FX as:

01 LBL^T FX

02 RAD

03 ENTER

04 ENTER

05 SIN

06 * 

07 RTN


Setting H to 10^-6  (1E-6):


DF:   f'(x)

x = 0.5, Result:  0.9182; x = 1.6, Result: 0.9530


LN:  ln f'(x)

x = 0.5, Result:  3.8305; x = 1.6, Result:  0.5959


PWR: with n = 3,   (f'(x))^3

x = 0.5; Result:  0.1583; x = 1.6;  Result: 7.3128



Example 2:  f(x) = x^2 + 3 * x + 1 = x * (x + 3) + 1


Set FX as:

01 LBL^T FX

02 ENTER

03 ENTER

04 3

05 +

06 *

07 1

08 + 

09 RTN


Setting H to 10^-6  (1E-6):


DF:   f'(x)

x = 3.2, Result:  9.4000; x = 6.8, Result: 16.6000


LN:  ln f'(x)

x = 3.2, Result:  0.4511; x = 6.8, Result: 0.2454


PWR: with n = 1.5,   (f'(x))^1.5

x = 3.2, Result:  64.3677; x = 6.8, Result: 204.7864



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. 


Saturday, December 4, 2021

HP 17B and HP 27S: Derivatives to the Nth Order (and TI-84 Plus CE Python 5.7 update)

 HP 17B and HP 27S: Derivatives to the Nth Order


With the Solver of the HP 17B family, HP 27S, and the HP 19B calculator, we can calculate derivatives of any order.  Four derivatives are presented here.  You can use any name you want other than those presented here.  Each derivative is to the kth order. 


Derivative 1:   d^k/dx^k a × x^n 


N and K must be positive integers, D is the value of the derivative  


DER1: D=A×X^(N-K)×PERM(N:K)


Example:

Input:  N = 2, K = 1, A = 3, X = 1.5

Result:  D = 9


Derivative 2:   d^k/dx^k e^(a × x) 


K must be a positive integer, D is the value of the derivative


DER2: D=A^K×EXP(A×X)


Example:

Input:  A = 1.8, K =3, X = 3

Result:  D = 213.4409


Derivatives 3 and 4 will require trigonometric functions, which are not available on the HP 17B family.   It is recommended you set the calculator to Radian angle mode.


Derivative 3:  d^k/dx^k sin(a × x)


DER3: D=IF(MOD(K:2)=0:(-1)^(K÷2)×A^K×SIN(A×X):(-1)^((K+3)÷2)×A^K×COS(A×X))


Examples:

Input:  A = 0.75, X = 0.66, K = 2

Result: D = -0.2672


Input:  A = 0.75, X = 0.66, K = 3

Result: D = -0.3712


Derivative 4:  d^k/dx^k cos(a × x)


DER4: D=IF(MOD(K:2)=0:(-1)^(K÷2)×A^K×COS(A×X):(-1)^(K÷2+1÷2)×A^K×SIN(A×X))


Examples:

Input:  A = 0.75, X = 0.66, K = 2

Result: D = -0.4950


Input:  A = 0.75, X = 0.66, K = 3

Result: D = 0.2004


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. 


Monday, November 8, 2021

Derivatives with Surprisingly Imaginary Results

Derivatives with Surprisingly Imaginary Results



Here are three derivatives of functions where complex numbers are involved with further algebraic simplification.  




d/dx √(a - x)^(1/2)



d/dx √(a- x)^(1/2)


= 1/2 ∙ (a - x)^(-1/2) ∙ -1


= -1/2 ∙ 1 ÷ (√(a - x))


Going a step further...


= -1/2 ∙ 1 ÷ (√(-1) ∙ √(x - a))


With √(-1) = i ,  1/i = -i


= i ÷ (2 ∙ √(x - a))



d/dx  arcsin(x + a)



d/dx arcsin(x + a)


= 1 ÷ √(1 - (x + a)^2)


= 1 ÷ √(1 - (x^2 + 2 ∙ a ∙ x + a^2))


= 1 ÷ √(-x^2 - 2 ∙ a ∙ x + 1 - a^2)


Factoring out -1 in the denominator: 


= 1 ÷ √((-1) ∙ (x^2 + 2 ∙ a ∙ x - 1 + a^2))


= 1 ÷ (i ∙ √(x^2 + 2 ∙ a ∙ x - 1 + a^2))


= -i ÷ √(x^2 + 2 ∙ a ∙ x - 1 + a^2)



d/dx e^(√(a - x)) 



d/dx e^(√(a - x)) 


= e^(√(a - x)) ∙ d/dx √(a - x)


= -e^(√(a - x)) ÷ (2 ∙ √(a - x))


With:  √(a - x) = i ∙ √(x - a) and e^(i ∙ Θ) = cos Θ + i ∙ sin Θ


= -e^(i ∙ √(x - a)) ÷ (2 ∙ i ∙ √(x - a))


= -e^(i ∙ √(x - a)) ÷ (2 ∙ i ∙ √(x - a))


=  i ∙ e^(i ∙ √(x - a)) ÷ (2 ∙ √(x - a))


= (i ∙ (cos √(x - a) + i ∙ sin √(x - a)) ÷ (2 ∙ √(x - a))


= (-sin √(x - a) + i ∙cos √(x - a)) ÷ (2 ∙ √(x - a))




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. 


Sunday, November 1, 2020

Book Review: Calculus for Middle Schoolers by Serena Swegle

 Book Review: Calculus for Middle Schoolers by Serena Swegle


Just The Facts


Calculus for Middle Schoolers


Author:  Serena Swegle


Publisher:  Sunhut Publishing


Cost:  $26.50 for Paperback, $9.99 for Kindle (as of 10/23/2020)


Link:  https://www.amazon.com/Calculus-Middle-Schoolers-Serena-Swegle/dp/057871275X/ref=sr_1_3?dchild=1&keywords=Calculus+for+Middle+Schoolers&qid=1603471676&sr=8-3


Topics Covered


The number e (2.718281828...)


The common logarithm  (base 10)


The natural logarithm (base e)


Trig Functions (sine, cosine, tangent)


Sums 


Limits


Derivative - the derivative of a polynomial


Integral - the integral of a polynomial


The Derivative and Integral of e^x


An Introduction to Calculus 


The target audience is middle school students.  However, book serves as a great introduction to calculus for high school and college students who are taking calculus for the first time.  The book gives a simple, concrete introduction to various subjects, in an easy-to-read narrative.  Calculus is a complex subject, and this book allows readers, who may be intimidated about the subject, to develop a understanding.   


I would recommend this book to be read prior to the student's first calculus class.   The book can be read in one or two days, but I feel it was meant to read as one chapter a time per day or week.   


Verdict


Swegle's book is well written, in a concise language.  The chapter covers one concept at the time, which serves as a great introduction to a rich subject.   The examples are simple and apply closely to the text.   I wish Swegle put a summary of all the topics covered at the end of the book as a wrap up.  Otherwise, I recommend this book for educators and parents.   For those who have the Kindle app, $9.99 is a good price point.  Recommended.


Thank you, Serena for recommending this book for me to review.  


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. 


Friday, April 27, 2012

Calculus Revisited #5: Derivatives

Welcome to entry #5 of 21 in our Calculus Revisited series. Today, we tackle derivatives!

First the formal definition.

Derivative:

df/dx = f'(x) =

lim ( f(x + δx) - f(x) ) / δx
δx → 0

Note that both symbols for derivatives, the quotient-like symbol and the use of the prime symbol are used interchangeably.

Use the derivative to:
1. Find the instantaneous rate of change at point x0 using the function f(x).
2. Find the slope at given point.
3. When given an equation dealing with the position of an object, f(t), you can find the velocity of an object by calculating f'(t).

But we are going to jump into doing the derivatives. Here is a basic of derivatives:

d/dx ( f(x) + g(x) ) = f'(x) + g'(x)
d/dx ( f(x) * g(x) ) = f'(x) * g(x) + f(x) * g'(x)
d/dx ( f(x) / g(x) ) = (g(x) * f'(x) - g'(x) * f(x))/(g(x)^2)
d/dx a = 0 (a is a constant)
d/dx x = 1
d/dx x^n = n * x^(n-1)
d/dx sin x = cos x
d/dx cos x = -sin x
d/dx tan x = sec^2 x
d/dx e^x = e^x
d/dx a^x = a^x ln a (a is a constant)
d/dx ln x = 1/x
d/dx asin x = 1/√ (1 - x^2)
d/dx acos x = -1/√ (1 - x^2)
d/dx atan x = 1/(x^2 + 1)

TIP: For d/dx ( f(x) / g(x) ), let N = f(x) (numerator) and D = g(x) (denominator). Then d/dx N / D = ( D * N' - D' * N)/(D^2)

Higher Order Derivative: Repeat the derivative operation on f(x).

f''(x) = d^2/dx^2 is the second derivative: take the derivative of f(x), twice.
f'''(x) = d^3/dx^3 is the third derivative: take the derivative of f(x), thrice (three times).
f^(n)(x) = d^n/dx^n is the nth derivative: take the derivative of f(x) n times.

Problems
1. Find the derivative of f(x) = x^2 + 2x + 3.

We can use the addition property to help us.

d/dx (x^2 + 2x + 3)
= d/dx (x^2) + d/dx (2x) + d/dx (3)
= 2x + 2 + 0
= 2x + 2

Remember, the derivative of a constant is 0.

2. Find the slope of f(x) = -x^5 + 2x - 1 at x = 1

First find the derivative
d/dx (-x^5 + 2x - 1)
= d/dx (-x^5) + d/dx(2x) - d/dx(1)
= -5x^4 + 2 - 0
= -5x^4 + 2
The slope is determined by calculating f'(1).
f'(1) = -5(1)^4 + 2 = -3

The slope of f(x) at x = 1 is -3.

3. Find the derivative of f(x) = x^2 * ln x.

Use the product rule: x^2 multiplied by ln x.

d/dx (x^2 * ln x)
= d/dx (x^2) * ln x + x^2 * d/dx (ln x)
= 2x * ln x + x^2 * 1/x
= 2x * ln x + x

4. Find the derivative of f(x) = (x^2 -1)/(x + 2)

Use the division rule: numerator is x^2 -1 and denominator is x + 2.

d/dx ((x^2 - 1)/(x + 2))
= ((x + 2) * d/dx(x^2 - 1) - (x^2 - 1) * d/dx(x + 2))/(x + 2)^2
= ((x + 2) * 2x - (x^2 - 1) * 1)/(x + 2)^2
= (2x^2 + 4x - x^2 + 1)/(x + 2)^2
= (x^2 + 4x + 1)/(x + 2)^2

5. Higher order derivatives: Find the first, second, and third derivative of f(x) = 3x^6 + 7x and g(x) = sin x respectively.


f(x) = 3x^6 + 7x
First Derivative
f'(x) = 18x^5 + 7
Second Derivative
f''(x) = 90x^4
Third Derivative
f'''(x) = 360x^3

g(x) = sin x
g'(x) = cos x
g''(x) = -sin x
g'''(x) = -cos x

6. An interesting property: d/dx( asin x + acos x)

d/dx(asin x + acos x)
= d/dx asin x + d/dx acos x
= 1/√(1-x^2) + (-1)/√(1-x^2)
= 0

This implies that the function asin x + acos x for all x. Bonus question: what is that constant?


Thanks for joining us. Next time we will work with an important rule in calculus: The Chain Rule.

This blog is property of Edward Shore. © 2012

By the way, the answer to the bonus question: asin x + acos x = π/2

RPN HP 12C: Fibonacci and Lucas Sequences

  RPN HP 12C: Fibonacci and Lucas Sequences Golden Ratio, Formulas, and Sequences Let φ be the Golden Ratio: φ = (1 + √5) ÷ 2...