Showing posts with label sine. Show all posts
Showing posts with label sine. Show all posts

Saturday, September 20, 2025

Trigonometric Calculus when Angles are in Degrees

Trigonometric Calculus when Angles are in Degrees


Today’s blog is a quickie.


The preferred angle measure in calculus is the radian. However, a lot of applications, including geometry, astronomy, engineering, and construction, use degrees.


An approach is to convert everything to radians before proceeding. Another approach is to remember that x radians = x° * π / 180, and use the conversion factor.



Derivatives



d/dx sin( x° )


Now all calculus calculations must have radians.


d/dx sin( x * π / 180)

= π / 180 * cos (x * π / 180)

= π / 180 * cos(x°)


Similarly – remember the angle considered is in DEGREES:

d/dx sin(x°) = π / 180 * cos(x°)

d/dx csc(x°) = - π / 180 * csc(x°) * cot(x°)

d/dx cos(x°) = - π / 180 * sin(x°)

d/dx sec(x°) = π / 180 * tan(x°) * sec(x°)

d/dx tan(x°) = π / 180 * sec(x°)^2

d/dx cot(x°) = -π / 180 * csc(x°)



Integration


Now let’s try integration.


∫( sin(x°) dx)

= ∫( sin(x * π / 180)) dx

= 180 / π * ∫(π / 180 * sin(x * π / 180)) dx

= 180 / π * -cos(x * π / 180) + C

= -180 / π * cos(x°) + C


Similarly:

∫ sin(x°) dx = -180 / π * cos(x°) + C

∫ cos(x°) dx = 180 / π * sin(x°) + C

∫ tan(x°) dx = -180 / π * ln(cos(x°)) + C



Use caution when using calculators. A lot of calculators when using calculus in degree mode get it correct but its’ always good to verify.



Eddie


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

The author does not use AI engines and never will.

Sunday, February 18, 2024

Casio fx-CG 50 CORDIC Simulation: Approximating Sine and Cosine of Angles

Casio fx-CG 50 CORDIC Simulation:  Approximating Sine and Cosine of Angles




Introduction - How Computers Calculate Mathematical Functions



First developed by Jack E. Volder, the Coordinate Rotation Digital Computer, better known as CORDIC, is an algorithm used to calculate many mathematical functions, including trigonometric functions, logarithms, exponentials, and hyperbolic functions.     CORDIC is a fundamental algorithm, which variants of CORDIC are used in computers and calculators.


Today's focus will be a calculating sines and cosines of angles.  The steps will be detailed in the next sections.  



CORDIC1:  Series of Arctangents


Let Θ be the angle.   The first step is to build Θ as additions and subtractions of terms of arctan(1 ÷ (2^n)), starting at n = 0 and stopping at the required accuracy.  Let A be the approximation.  


Examples: 


Θ = 45° requires only one term:

A = 45° = arctan 1


Θ ≈ 71.56505118°

 A = 71.56505118° = arctan 1 + arctan 1/2


Θ ≈ 32.47119229°

A = 32.47119229° = arctan 1 - arctan 1/2 + arctan 1/4


A series to recreate Θ = 30° takes 32 terms of ±arctan (1 ÷ 2^n) from n = 0 to n = 31.   (8 decimal places)  This is known as coordinate rotation.


The program CORDIC1 determines the number of terms need to created to obtain Θ.   Accuracy in this code is set to 5 decimal places, but can be adjusted (see the line in blue).  


Casio fx-CG 50 Program Code:  CORDIC1


Deg

"ANGLE"?->Θ

0->I

0->A


Lbl 0

tan^-1 (2^(-I))->T

If A<Θ

Then 

A+T->A

Else 

A-T->A

IfEnd


I+1->I


Abs (A-Θ)>1×10^-5=>Goto 0


ClrText

Blue Locate 1,3,"Θ: "

Blue Locate 5,3,Θ


Red Locate 1,4,"A: "

Red Locate 5,4,A


Green Locate 1,7,I


Notes:

-> is the store arrow →

=> is the jump command ⇒


For reference:


arctan 1 = 45°

arctan 1/2 ≈ 26.56505118°

arctan 1/4 ≈ 14.03624347°

arctan 1/8 ≈ 7.125016349°

arctan 1/16 ≈ 3.576334375°

arctan 1/32 ≈ 1.789910608°


CORDIC2:  Calculating Sine and Cosine


Imagine the coordinate (cos Θ, sin Θ) on a unit circle.  A unit circle is a circle with radius of length 1 and center located at the origin (0,0).   


Set the initial angle at 0°.  Then x = cos 0° = 1 and y = sin 0° = 0.   The initial vector is set to be [ [ cos 0° ] [ sin 0° ] ] = [ [ 1 ] [ 0 ] ].


Approximate Θ in terms of arctangent (1 ÷ (2^n)), starting at n = 0.  



Direction of Rotation


Set σ as the direction of rotation.    


A rotation is positive if we add arctan(1 ÷ (2^n)) to A.    For a positive rotation, set σ_i = +1.   


A rotation is negative if we subtract arctan(1 ÷ (2^n)) to A.    For a negative rotation, set σ_i = -1.   


For example:


 Θ ≈ 32.47119229°

A = 32.47119229° = arctan 1 - arctan 1/2 + arctan 1/4


Then:  σ_0 = 1 (positive rotation), σ_1 = -1 (negative rotation), σ_2 =  1 (positive rotation).  



Multiplying Factor


The number of iterations is also used to determine the required multiplication factor:


n = Π( 1 ÷ √(1 + 2^(-2 × I)), I = 0 to I = terms needed - 1)


For the example:


 Θ ≈ 32.47119229°

Needed 3 iterations, i_0 to i_2.  


Then:

n = 1 ÷ √(1 + 2^(-2 × 0)) × 1 ÷ √(1 + 2^(-2 × 1)) × 1 ÷ √(1 + 2^(-2 × 2))

= 4 × √170 ÷ 85

≈ 0.6135719911



Calculating the Next Iteration


The next iteration for x and y are:


x_i+1 = x_i - 2^(-i) × σ_i × y_i


y_i+1 = 2^(-i) × σ_i × x_i + y_i


When A is sufficiently near or equal to Θ, the cosine and sine are approximated as:


cos(A) ≈ n × x_final


sin(A) ≈ n × y_final


For the example:

 Θ ≈ 32.47119229°


The approximated angle, in this case, happens to be exact angle, A = Θ.  And,

cos(A) ≈ 0.8436614877 

sin(A) ≈ 0.5368754922


For more details, please check out resources in the Sources section.   I particularly like Oxford's A Very Short Introduction series.  



Casio fx-CG 50 Program Code:  CORDIC2


This algorithm is adopted from the Python example (see Wikipedia article).  


Deg

"ANGLE"?->Θ


0->I

0->A

1->X

0->Y

1->N


Lbl 0

tan^-1 (2^(-I))->T

If A<Θ

Then 

A+T->A

1->S

Else 

A-T->A

-1->S

IfEnd

N÷√(1+2^(-2*I))->N

X-S*2^(-I)*Y->P

Y+X*S*2^(-I)->Q

P->X

Q->Y


I+1->I


Abs (A-Θ)>1×10^-5=>Goto 0

X*N->X

Y*N->Y


ClrText

Blue Locate 1,3,"Θ: "

Blue Locate 5,3,Θ


Red Locate 1,4,"A: "

Red Locate 5,4,A


Black Locate 1,5,"cos :"

Black Locate 7,5,X

Black Locate 1,6,"sin :"

Black Locate 7,6,Y


Green Locate 1,7,I



CORDIC3:  Doing it without a Arctangent function


In reality, most of the time the arctangent function also has to be approximated.   There are many ways to approximate, which varying accuracy.   I used the fx-CG50's statistics mode to come up with a regression equation with the following lists:


x_list = sequence of 1÷(2^i) from i = 0 to i = 39 


y_list = sequence of arctan(1÷(2^i)) from i = 0 to i = 39


Of the regression models the fx-CG50 offers, the best regression model is quartic regression (4th-order polynomial):


y ≈ 9.43597784 × x^4 - 22.116232 × x^3 + 0.40116676 × x^2 + 57.2790727 × x + 1.4558 × 10^-5


Remember that I am working with degree angle measurement.  





Casio fx-CG 50 Program Code:  CORDIC3


Deg

"ANGLE"?->Θ


0->I

0->A

1->X

0->Y

1->N


Lbl 0

2^(-I)->K

9.43597784917955K^(4)-22.1162323028173K^(3)+

0.401166766193516K^2+57.2790727477367K+

1.45584715586876×10^-5->T


If A<Θ

Then 

A+T->A

1->S

Else 

A-T->A

-1->S

IfEnd

N÷√(1+2^(-2*I))->N

X-S*2^(-I)*Y->P

Y+X*S*2^(-I)->Q

P->X

Q->Y


I+1->I


Abs (A-Θ)>1×10^-5=>Goto 0

X*N->X

Y*N->Y


ClrText

Blue Locate 1,3,"Θ: "

Blue Locate 5,3,Θ


Red Locate 1,4,"A: "

Red Locate 5,4,A


Black Locate 1,5,"cos :"

Black Locate 7,5,X

Black Locate 1,6,"sin :"

Black Locate 7,6,Y


Green Locate 1,7,I


For the example:

 Θ ≈ 32.47119229°


Approximating Θ within 8 decimal places (10^-5) yields these results:

A:  32.47118598

cos A:  0.8436683456

sin A:  0.5368647154

24 terms used



Sources


"CORDIC"  Wikipedia.   Last Edited January 11, 2024.   Accessed January 12, 2024.  https://en.wikipedia.org/wiki/CORDIC


Brummelen, Glen Van.  Trigonometry:  A Very Short Introduction  Oxford University Press: Oxford, United Kingdom.  2020.  ISBN 978-0-19-881431-3



Eddie


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

Casio fx-CG 50 and fx-9750GIII: Regression Builder

Casio fx-CG 50 and fx-9750GIII:  Regression Builder


Introduction


The program LRBUILD lets the user fit bi-variate data (x,y) to a customized regression equation in the form:


y = C + Σ Cₙ * fₙ(x) 


where:


C = constant term.  This term is automatically calculated for by the program.


Cₙ = coefficient of each subsequent term of fₙ(x)


fₙ(x) = function, where the user can choose any of the following forms:


1.  x^A

2.  ln(A * x)

3.  e^(A * x)

4.  sin(A * x)


where A is a real number.  Angles are assumed to be in radian measure.  


For example, we can fit data by least squares method to this equation:


y = C + C_1 * x^2 + C_2 * e^(0.5 * x) + C_3 * sin(x)


You can add as many fₙ(x) terms as you like.


The program will give you the coefficients in a vertical matrix, starting from C and so forth, and the R^2 goodness of fit:


R^2 = 1 - SS_res / SS_tot


SS_res = Σ( y_observed - y_predicted)^2


SS_tot = Σ(y_observed - mean(y_oberserved))^2



Notes:


The characters _n (lower subscript n) and Σ (sigma symbol) are found on the CHAR (Character Select) on the programming editor menu (almost exit until the soft menu TOP, BOTTOM, SEARCH, ... displays).


The lines:


For 1 → I To 750

Next


are used to create a short pause.


There are two versions:  


Program files with the g3m extension is for the color Casio graphing calculators, such as the fx-CG50.   You can download this file here:

https://drive.google.com/file/d/1YidknrzjU_oRT3KLIzkEogbU_XFBCH0j/view?usp=sharing



Program files with the g1m extension is for the monochrome Casio graphing calculators, such as the fx-9750GIII (United States) and the fx-9860GIII (International).  You can download this file here:

https://drive.google.com/file/d/1GOO6VHGV_JRlNlbZB8ww3hK1qDqZaag_/view?usp=sharing



To transfer between Casio calculators, it is recommended to save them as text files.  Then transfer to the SAVE-F folder and load it on the home calculator.  Some editing may be necessary, such as <-1> with x^-1.


Casio fx-9750gIII and fx-CG50 (and probably most other Casio modern graphing calculators) Program: LRBUILD

(Extra spaces included for readability - this meant to be typed on the calculator)


Rad

ClrText

Locate 1,1,"LIN REG BUILDER"

Locate 1,2,"EWS 2022-01-17"

Locate 1,3,"Y=C+Σ(C_n×F_n(X))"   (n is the lower script n from the CHAR screen)

For 1 → I To 750

Next

"X DATA"? → List 1

"Y DATA"? → List 2

Dim List 1 → N

Dim List 1 → Dim List 3

{0} → List 4

{0} → List 5

Seq(1,X,1,N,1) → List 6

List→Mat(List 6) → Mat A

List→Mat(List 2) → Mat B

"CONSTANT TERM ADDED"

For 1 → I To 750

Next

Lbl 0

Menu "TERM?", "X^A", 1, "ln (AX)", 2, "e^(AX)", 3, "sin (AX)", 4, "CALCULATE", 5

Lbl 1

"A"? → A

Augment(List 4, {1}) → List 4

Got A

Lbl 2

"A"? → A

Augment(List 4, {2}) → List 4

ln(A×List 1) → List 6

Goto A

Lbl 3

"A"? → A

Augment(List 4, {3}) → List 4

e^(A×List 1) → List 6

Goto A

Lbl 4

"A"? → A

Augment(List 4, {4}) → List 4

sin(A×List 1) → List 6

Goto A

Lbl A

Augment(List 5, {A}) → List 5

List→Mat(List 6) → Mat D

Augment(Mat A, Mat D) → Mat A

Goto 0

Lbl 5

Dim List 4 → M

(Trn Mat A × Mat A)^-1 × Trn Mat A × Mat B → Mat C

"COEFFS:" ◢

Mat C ◢  

For 1 → I to N

0 → Y

For 1 → J To M

List 4[ J ] → L

List 5[ J ] → A

Mat C[ J, 1 ] → C

List 1[ I ] → X

L = 0 ⇒  Y + C → Y

L = 1 ⇒ Y + C × X^A → Y

L = 2 ⇒ Y + C × ln(AX) → Y

L = 3 ⇒ Y + C × e^(AX) → Y

L = 4 ⇒ Y + C × sin(AX) → Y

Next

Y = 0 ⇒ 1E-7    (lower case 10 on the fx-CG 50)

Y → List 3[ I ]

Next

1 - (Sum (List 2 - List 3)^2)÷(Sum (List 2 - Mean(List 2))^2) → R

"R^2="

R ◢

List→Mat(List 1, List 2, List 3) → Mat D



Variables:


List 1:  X Data

List 2:  Y Data

List 3:  Expected Y Data (Calculated)

List 4:  Operation Types:  0 - constant, 1 - x^a, 2 - ln(a*x), 3 - e^(a*x), 4 - sin(a*x)

List 5:  A


Mat A:  X data matrix 

Mat B:  Y data matrix

Mat C:  matrix of calculated coefficients



Examples


Example 1:

Fit the following data:


x data = {10, 25, 34, 46, 65}

y data = {39.7, 100, 135.9, 183.9, 260}


to the curve y = C + C1 * x + C2 / x


Remember the constant term is automatic.   

On the TERM? menu, select 

1.  X^A with A = 1

1.  X^A (again), this time with A = -1

5.  CALCULATE


Calculated coefficients:

[[ 0.1012904425 ]

[ 3.99874051 ]

[ -3.775351133 ]]


y = 0.012904425 + 3.99874051x - 3.775351133/x


R^2 = 0.9999994909


y' predicted data: 

{39.71116043, 99.91878916, 135.947281, 183.9612811, 259.9613413}


Example 2:

Fit the following data:


x data = {-0.35, -0.16, 0.27, 0.84}

y data = {-0.64, -0.31, 0.58, 2.06}


to the curve y = C + C1 * sin x  + C2 * e^x


Remember the constant term is automatic.   

On the TERM? menu, select 

4.  sin(A*X) with A = 1

3.  e^(A*X) with A = 1

5.  CALCULATE


Calculated coefficients:

[[ -0.9847711767 ]

[ 1.023495272 ]

[  0.9854914931 ]]


y = -0.9847711767 + 1.023495272 * sin x + 0.9854914931 * e^x


R^2 = 0.9999986129


y' predicted data:

{-0.6412613439, -0.3080521531, 0.5791860102, 2.060127487}


Example 3:

Fit the following data:


x data = {2, 3, 4, 5, 6}

y data = {22.5, 34, 45.5, 57.5, 69.75}


to the curve y = C + C1 * x^1.2 + C2 * ln(3*x)


Remember the constant term is automatic.   

On the TERM? menu, select 

1.  X^A with A = 1.2

2.  ln(A*X) with A = 3

5.  CALCULATE


Calculated coefficients:

[[ -0.08646217016 ] 

[ 6.83429695 ]

[ 3.855357541 ]]


y = -0.08646217016 + 6.83429695 * x^1.2 + 3.855357541 * ln(3* x)


R^2 = 0.9999924407


y' predicted data:

{22.52250254, 33.92570965, 45.56537698, 57.50145068, 69.73496014}


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

March Calculus Madness Sweet Sixteen - Day 13: Some Double Integrals

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


Welcome to March Calculus Madness!


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



Double Integration Time


(I) 

∫ ∫ sin(a*x + b*y) dx dy

= ∫ -1/a * cos(a*x + b*y) + C1 dy

= -1/(a*b) * sin(a*x + b*y) + C1*y + C2


(II) 

∫ ∫ sin(a*x + b*y) dy dx

= ∫ -1/b * cos(a*x + b*y)+ C1 dx

= -1/(a*b) * sin(a*x + b*y) + C1 * x + C2


For (I) and (II) to equal,  x = y


(III)

∫ ∫ e^(a*x + b*y) dx dy

= ∫ 1/a * e^(a*x + b*y)+ C1 dy

= 1/(a*b) * e^(a*x + b*y) + C1 * y + C2


(IV)

∫ ∫ e^(a*x + b*y) dy dx

= ∫ 1/b * e^(a*x + b*y) + C1  dx

= 1/(a*b) * e^(a*x + b*y) + C1 * x + C2


For (III) and (IV) to be equal, x = y


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. 


Tuesday, March 22, 2022

March Calculus Madness Sweet Sixteen - Day 7: ∫ 1/(1 + cos x) dx and ∫ 1/(1 + sin x) dx

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


Welcome to March Calculus Madness!


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


∫ 1/(1 + cos x) dx and ∫ 1/(1 + sin x) dx



To tackle these integrals, we will make use of the following derivatives and trig identities:


d/dx tan x = sec^2 x dx


d/dx cot x = -csc^2 x dx


d/dx csc x = -cot x * csc x


d/dx sec x = tan x * sec x


sin^2 x + cos^2 x = 1


cot x = 1/tan x,  csc x = 1/sin x,  sec x = 1/cos x


∫ 1/(1 + cos x) dx

= ∫ 1/(1 + cos x) * (1 - cos x)/(1 - cos x) dx

= ∫ (1 - cos x)/(1 - cos^2 x) dx

= ∫ (1 - cos x)/sin^2 x dx

= ∫ csc^2 x - cot x * csc x dx

= -cot x + csc x + C


∫ 1/(1 + sin x) dx

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

= ∫ (1 - sin x)/(1 - sin^2 x) dx

= ∫ (1 - sin x)/(cos^2 x) dx

= ∫ sec^2 x - tan x * sec x dx

= tan x - sec x + C



Note:  CAS systems in graphing calculators will default to using sin x, cos x, and tan x.  


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, November 27, 2021

Casio fx-CG50: Integer Digit Operations

Casio fx-CG50: Integer Digit Operations


Sum of the Digits and Digital Sum with Memory


The sum of the digits is pretty much a straight forward calculation, separate all the digits and add them up.  Example:


N = 18,283


Sum of the digits: S = 1 + 8 + 2 + 8 + 3 = 22


Ernesto Estrada, author of the article "Integer-Digit Functions: An Example of Math-Art Integration" (see the Source Section below), introduces the sum of the digits with memory, which is defined as:


F = N × S 


Going with our example, N = 18,283.  With S = 22,


F = 18,283 × 22 = 402,226


The program INTDGT, programmed on the Casio fx-CG50, calculates the sum of a digits of a positive integer and the digital sum of the memory.


Variables:

N = input

S = sum of the digits

F = digital sum with memory

List 1 = list where each element is a digit of N


Casio fx-CG50 Program:  INTDGT


"2021-09-21 EWS"

"N>0, INTEGER "? → N

N → A

Int log N → L

Seq(0,x,0,L,1) → List 1

For 1 → K To L+1

Int (A÷10^L) → List 1[K]

A-List 1[K]×10^L → A

L-1 → L

Next

Sum List 1→ S

S×N → F

"SUM OF DIGITS="

S ◢

"S×N="

F ◢

"DIGITS IN List 1"

List 1


Sum of Digits as Functions Applied to Each Digit


The program FNDGT calculates the sum of each digit and returns a list in a four element list:


{ Σ (n_k),  Σ (n_k)^2,  Σ sin(n_k), Σ cos(n_k) }


Radians angle mode is used.  The results are stored in List 2.


Casio fx-CG50 Program:  FNDGT


"2021-09-21 EWS"

Rad

"N>0, INTEGER"? → N

N → A

Int log N → L

{0,0,0,0} → List 2

For L → K To 0 Step -1

Int (A÷10^K) → M

List 2[1] + M → List 2[1]

List 2[2] + M^2 → List 2[2]

List 2[3] + sin M → List 2[3]

List 2[4] + cos M → List 2[4]

A - M×10^K → A

Next

"K, K^2, sin K, cos K" ◢

List 2


Example: 

N = 93,259


Results:

{ 28, 200, 0.9157301307, -2.944737671 }


Integers and Art


I encourage everyone to read the article listed in the source section below.   Ernesto Estrada demonstrates how to turn the sum of a digits and applying functions to the digits into beautiful art:   grass, fish, asteroids, butterflies, and other beautiful patterns.  If you have the chance, get this article while it is Open Access!  


Source:


Estrada, Ernesto  "Integer-Digit Functions:  An Example of Math-Art Integration"  The Authors, Volume 40, Number 1, 2018.   https://link.springer.com/article/10.1007%2Fs00283-017-9726-x

Retrieved September 15, 2021.   Open Access*


*as of 9/15/2021 


In a few days the 2021 calendar will just be one page.


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. 


Saturday, December 5, 2020

HP 71B: Sign "Graph" of Trig Functions

 HP 71B: Sign "Graph" of Trig Functions


Introduction


The program SGNTRIG builds a 22 character binary string that depends on the function:


g(x) = 

1  if  sgn(t(x/c)) > 1

0  if  sgn(t(x/c)) ≤ 0


where:


c is a scaling factor, 


sgn(x) is the sign function,  and


t(x) represents one of three trigonometric functions, sin(x), cos(x), or tan(x).   Angles are assumed to be radians.


If we set to scale to c = 1, then g(x) takes the integer values from 1 to 22.  


The HP 71B builds the result to the string S$.   This is an aid to visualize at least some of the graph.   When the bit is 1, the graph is above the x-axis, otherwise, the graph is either on or below the x-axis.  The program presented can be expanded or modified to explore other functions.


The resulting string is a "psuedo-graph".  


Below is a graphical representation of g(x) (an HP Prime is used to graph g(x)).


HP 71B Program SGNTRIG

Size:  270 bytes


100 DESTROY S,I,N,E,C

105 S$=""

110 RADIANS

115 INPUT 'SCALE? ';C

120 DISP "S:SIN C:COS T:TAN"

125 E$=KEY$

130 IF E$="S" OR E$="C" OR E$="T" THEN 200 ELSE 120


200 FOR I=1 TO 22

205 IF E$="S" THEN N=SGN(SIN(I/C))

210 IF E$="C" THEN N=SGN(COS(I/C))

215 IF E$="T" THEN N=SGN(TAN(I/C))

220 IF N=1 THEN N=1 ELSE N=0

225 S$=S$&STR$(N)

230 DISP S$ @ BEEP 589,0.1 @ WAIT 0.2

235 NEXT I

240 DISP S$ @ BEEP 661,2


Notes:


Line 105:  creates a blank string, which is allowed on the HP 71B


Line 125:  The KEY$ function calls for a key input. S for sine, C for cosine, and T for tangent.


Lines 205 to 215: determine which trigonometric function to use


Line 220:  Sets the character to 0 if the sign function returns 0 or -1


Line 225:  &, the ampersand symbol concatenates two strings


Lines 230 and 240, respectively:  589 Hz is middle D, 661 Hz is middle E


Example


Below are results for each of the trigonometric functions when scale is set to 1.  




YouTube video: https://www.youtube.com/watch?v=GL6urOGvRGY&feature=youtu.be

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, October 10, 2020

Sines and Cosines: Adding and Subtracting Angles

 Sines and Cosines:   Adding and Subtracting Angles





Note:   


π/2 radians = 90°,   π radians = 180°


Sine


sin(x + π/2) = sin(x) cos(π/2) + cos(x) sin(π/2) = cos(x)


sin(x - π/2) = sin(x) cos(π/2) - cos(x) sin(π/2) = -cos(x)


sin(π/2 - x)  = sin(π/2) cos(x) - cos(π/2) sin(x) = cos(x)


sin(x + π) = sin(x) cos(π) + cos(x) sin(π) = -sin(x)


sin(x - π) = sin(x) cos(π) - cos(x) sin(π) = -sin(x)


sin(π - x)  = sin(π) cos(x) - cos(π) sin(x) = sin(x)


Cosine


cos(x + π/2) = cos(x) cos(π/2) - sin(x) sin(π/2) = -sin(x)


cos(x - π/2) = cos(x) cos(π/2) + sin(x) sin(π/2) = sin(x)


cos(π/2 - x) = cos(π/2) cos(x) + sin(π/2) sin(x) = sin(x)


cos(x + π) = cos(x) cos(π) - sin(x) sin(π) = -cos(x)


cos(x - π) = cos(x) cos(π) + sin(x) sin(π) = -cos(x)


cos(π - x) = cos(π) cos(x) + sin(π) sin(x) = -cos(x)


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. 


Thursday, November 15, 2018

TI-84+ and Casio (fx-CG 50) Micropython: Simplifying A sin x + B cos x To r sin (x + θ)

TI-84+ and Casio (fx-CG 50) Micropython:  Simplifying  A sin x + B cos x To r sin (x + θ)

Introduction

Simplify the expression:

(I)   a * sin x + b * cos x

to an expression that involves only one trigonometric function. 

The first task is to multiply the expression by √(a^2 + b^2)/√(a^2 + b^2). (refer to Source)  This results as:

(II) a* √(a^2 + b^2)/√(a^2 + b^2) * sin x + b * √(a^2 + b^2)/√(a^2 + b^2) * cos x

Refer to the triangle diagram below and it will should become clear why it is desirable to multiply by √(a^2 + b^2)/√(a^2 + b^2). 



With:

(III)
 √(a^2 + b^2) * a/√(a^2 + b^2) * sin x +  √(a^2 + b^2) * b/√(a^2 + b^2) * cos x
=  √(a^2 + b^2) * cos θ * sin x +  √(a^2 + b^2) * sin θ * cos x
=  √(a^2 + b^2) * (cos θ * sin x +  sin θ * cos x)

With the use of the trigonometric identity:
sin(x + y) = sin x * cos y + cos x * sin y

This becomes:
(IV)
 =  √(a^2 + b^2) * sin(x + θ)

Let's make some observations.

1.  The angle θ dependents on what quadrant the point (a,b) is. 

2.  Taking into consideration of where the point (a,b) is and the expression √(a^2 + b^2), the task of finding the coefficients of reduced formula for a * sin x + b* cos x can be achieved by calculating a rectangular to polar conversion of the point (a,b). 

Hence: (IV) becomes:

(V)
 a * sin x + b * cos x =  r * sin(x + θ)

where
r = √(a^2 + b^2)  = abs(a + bi)
θ = atan(b/a) = atan2(b,a) = arg(a + bi)


TI 84 Plus Program:  SCTOSIN

"EWS 2018-11-12"
a+bi
Disp "A*sin(X)+B*cos(X)", "=R*sin(X+θ)"
Prompt A,B
abs(A+B*i)→R
angle(A+B*i)→θ
Disp R,"sin(X+", θ, ")"

Casio Micropython (fx-CG 50) Script scotosin.py

import math
print("a*sin(x)+b*cos(x)")
print("=r*sin(x+t)")
a=float(input("a:"))
b=float(input("b:"))
r=math.sqrt(a**2+b**2)
t=math.atan2(b,a)
print(" ")
print(r)
print("*sin(x+")
print(t,")")

Examples
(Radians mode assumed)

Example 1:
4 * sin x + 2 * cos x = 4.472135955 * sin(x + 0.463647609)

Input:
a = 4
b = 2

Output:
r = 4.472135955
θ = 0.463647609



Example 2:
3 * sin x - 5 * cos x = 5.803951895 * sin(x - 1.030376827)

Input:
a = 3
b = -5

Output:
r = 5.803951895
θ = -1.030376827


Source:
Dugopolski, Mark  Trigonometry Addison Wesley: Boston 2003 pp 211-212  ISBN 0-201-70338-6

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, 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.

The MU Key on a Four Function Calculator and Programs for the DM42/HP 42S

  The MU Key on a Four Function Calculator and Programs for the DM42/HP 42S Not too long ago, I purchased this very colorful, four funct...