Showing posts with label nested radicals. Show all posts
Showing posts with label nested radicals. Show all posts

Wednesday, January 30, 2019

HP 71B: Product of f(x), Nested Radicals, How Much Can I Afford?, Cardiac Analysis

HP 71B:  Product of f(x), Nested Radicals, How Much Can I Afford?, Cardiac Analysis

Product of a Function

∏ f(x)

Edit f(x) at line 10

PROGRAM PRODFX
At least 90 bytes, 1/23/2019

10 DEF FNF(X)=[ insert f(X) here ]
20 INPUT "Lower=";L
30 INPUT "Upper=";U
40 P=1
50 FOR X=L TO U @ P=P*FNF(X) @ NEXT X
60 DISP 'P=';P

Example:  f(X) = FNF(X) = 1/X
Lower:  1
Upper:  5
Result:  6.61375661376E-6

Trigonometric Simplification

Original blog entry (11/15/2018):  http://edspi31415.blogspot.com/2018/11/ti-84-and-casio-fx-cg-50-micropython.html

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

Simply the expression:

a sin x + b cos x = r * sin( θ + x )
where r = √(a^2 + b^2), θ = angle(a,b) = arg(a+bi)

PROGRAM SCTOSIN
114 bytes, 1/23/2019

10 DESTROY A,B,R,T
20 RADIANS
30 DISP "A*SIN(X)+B*COS(X)" @ PAUSE
40 INPUT "A=";A
50 INPUT "B=";B
60 R=SQR(A^2+B^2) @ T=ANGLE(A,B)
70 DISP R;"*SIN(";T;"+X)"

Line 70 can use PRINT
SQR is √

Example: 
A = 2.25,  B = 1.76
Result:
R = 2.85658887486  (scroll left)
θ = .663806440909
Output:
2.85658887486  *SIN( .663806440909 +X)

How Much Car Can You Afford?

Original blog entry (3/13/2018):  https://edspi31415.blogspot.com/2018/03/hp-prime-car-payment-and-affordability.html

Calculate how much the buyer can afford, considering sales tax, discounts, and down payment.  All amounts are entered as positive.

PROGRAM AFFORD
221 bytes, 1/24/2019

10 DESTROY N,I,S,X,W,D,P
20 INPUT "# MONTHS:";N
30 INPUT "RATE %:";I @ I=I/1200
40 INPUT "PAYMENT $";X
50 INPUT "SALES TAX %:";S
60 INPUT "DISCOUNT %:";D
70 INPUT "DOWN PMT $";W
80 P=1/I*(1-(1+I)^(-N))
85 P=P*X
90 P=(P+W)/((1+.01*S)*(1-.01*D))
95 PRINT USING "'AMT: $'7D.DD";P

Example:
Term: N = 60 months
Interest Rate:  I = 4.8%
Desired Payment: X = $295
Sales Tax: S = 9.5%
Discount: D = 10%
Down Payment: W=$1500

Result:
AMT: $17657.09

HP 71B: Cardiac Programs

Source:  Hewlett Packard.  "HP-65 Medical Pac 1" 1974.

Valve Area

Variables:

Input:
P = pressure gradient data (mmHg), enter an average or data points
C = cardiac output (CO) (l/min)
R = R-R interval (seconds)
T = the time the valve is open (seconds)

The program offers a choice between calculating an  area of a regular valve or a mitral valve.

Program VALVE
433 bytes, 1/28/2019

10 DESTROY K,P,N,D,P1,C,R,T,F,V
20 P1=0 @ N=0 @ P=0
30 PRINT "PRESSURE (mmHg)" @ WAIT .5
35 INPUT "P: 1=AVG 2=DATA ";K
38 IF K=1 THEN 50 ELSE 40 
40 INPUT "P DATA: ";D
42 P=P+D @ N=N+1 @ P1=P/N
44 INPUT "DONE? 1=YES 2=NO ";K
46 IF K=2 THEN 40 ELSE 60
50 INPUT "P AVG. :";P1
60 INPUT "CO (l/min): ";C
62 INPUT "R-R (sec): ";R
64 INPUT "OPEN TIME (sec/min):";T
66 F=C*R/(60*T) @ V=F/(.0445*SQR(P1))
68 INPUT "MITRAL 1=YES 2=NO ";K
70 IF K=1 THEN LET V=V/.7
72 PRINT "MEAN FLOW (l/sec) :";F @ PAUSE
74 PRINT "AREA (cm^2) :";V

Anatomic Shunts

The program SHUNTS calculates the bi-directional shunts as a percentage.  The shunts are R-L (right-left) shunt and the L-R (left-right) shunts.

Variables:

Input:
R1:  right pulmonary artery
R2:  right atrium
L1:  left pulmonary artery
L2:  left ventricle

Program SHUNT
230 bytes, 1/27/2019

10 DESTROY L1,L2,R1,R2,L3,R3
20 INPUT "R-PULMONARY%:";R1
30 INPUT "R.ATRIUM%:";R2
40 INPUT "L-PULMONARY%:";L1
50 INPUT "L.ATRIUM%";L2
60 R3=(L1-L2)/(L1-R2)*100
65 L3=(R1-R2)/(L1-R2)*100
70 PRINT USING ' "R-L SHUNT:"4D.DD"%" ';R3 @ PAUSE
75 PRINT USING ' "L-R SHUNT:"4D.DD"%" ';L3 
90 END

Stroke Work

The program STRKWORK calculates stroke work and stroke work index based on pressure, cardiac output (CO), R-R interval (seconds), and body surface area (BSA).  The BSA is optional but is needed to calculate stroke work index. 

Program STRKWORK
404 bytes, 1/28/2019

10 DESTROY S,S1,P,P1,R,C,N,K,D,B
14 DISP "P=PRESSURE mmHg" @ WAIT .5
20 N=0 @ P=0
25 INPUT "P 1:AVG 2:DATA ";K
30 IF K=1 THEN 50
40 INPUT "P. DATA PT: ";D
42 P=P+D @ N=N+1 @ P1=P/N
44 INPUT "DONE? 1=YES 2=NO ";K
46 IF K=2 THEN 40 ELSE 60
50 INPUT "AVG P: ";P1 
60 INPUT "R-R INTERVAL (sec):";R
62 INPUT "CO (L/MIN): ";C
70 S=13.6*P1*C*R/60
72 PRINT "SW =";S;"(gm m)" @ PAUSE
80 INPUT "BSA? (m^2) (0=NONE): ";B
82 IF B=0 THEN 90
84 S1=S/B
86 PRINT "SWI: ";S1;"gm m/m^2"
90 END

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, November 17, 2018

TI-84+ and Casio (fx-CG 50) Micropython: Simplifying Nested Radicals

TI-84+ and Casio (fx-CG 50) Micropython: Simplifying Nested Radicals

Introduction 

The following program will simplifying the following expression:

√(x + y) = √a + √b

The input is x and y, with output a and b.  The following conditions are implied:  x > y and x > 0.

To see the derivation of simplification and examples, please check out this blog entry:

https://edspi31415.blogspot.com/2018/11/simplifying-nested-radicals.html

TI 84 Plus Program:  DENEST

"EWS 2018-11-12"
Disp "√(X+Y)=√(A)+√(B)","X>Y","X>0"
Prompt X,Y
X/2+1/2*√(X^2-Y^2)→A
X/2-1/2*√(X^2-Y^2) →B
√(A)→Z
round(Z,9)→Z
Disp " "

If Y<0 font="">

Then
If fPart(Z)=0
Then 
Disp √(A),"- √(",B,")"
Else 
Disp "√(",A,")- √(",B,")"
End

Else
If fPart(Z)=0
Then 
Disp √(A),"+ √(",B,")"
Else 
Disp "√(",A,")+ √(",B,")"
End

End

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

Input is the form of:

√(x1 * √x2 + y1 * √y2) = √a + √b

import math
print("sqrt(x+y)=")
print("sqrt(a)+sqrt(b)")
print("x>y","x>0")

print(" ")
print("x1*sqrt(x2)")
x1=float(input("x1:"))
x2=float(input("x2:"))
x=x1*math.sqrt(x2)

print(" ")
print("y1*sqrt(y2)")
y1=float(input("y1:"))
y2=float(input("y2:"))
y=y1*math.sqrt(y2)

a=x/2+math.sqrt(x**2-y**2)
b=x/2-math.sqrt(x**2-y**2)
z=math.sqrt(a)
z=round(z,10)
a=round(a,10)
b=round(b,10)

if y<0: font="">
  if z-int(z)==0:
    print(z,"-sqrt(")
    print(b,"?")
  else:
    print("sqrt(",a)
    print("-sqrt(")
    print(b,")")
else:
  if z-int(z)==0:
    print(z,"+sqrt(")
    print(b,")")
  else:
    print("sqrt(",a)
    print("+sqrt(")
    print(b,")")


Source:

Michael J. Wester, Editor.  Computer Algebra Systems: A Practical Guide John Wiley & Sons: Chichester 1999.  ISBN 978-0-471-983538

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.

Monday, November 5, 2018

Simplifying Nested Radicals

Simplifying Nested Radicals

Introduction

A nested radical is a radical of the form:

√(x_0 + √(x_1 + √(x_2 + .... + √(x_k) ... )))

A expression of radicals (not necessarily square roots) that contains radicals or surds (unresolved n th roots).  Example of a nested radicals include:

√(8 +  √3)

√(8 +  2 * √3)

√(√8 +  √3)

√(√8 -  √3)

This blog entry will deal with the denesting the following:

√(x + y) and √(x - y) where x and/or y is a radical.  Let's assume that x > y and only principal roots are calculated. We're looking into a neat process that is used in computer algebra systems.

Derivation

We want to obtain the following and determine a and b. 

(I) √(x + y) = √a + √b

and

(II) √(x - y) = √a - √b


Start by squaring both sides of (I):

(√(x + y))^2 = (√a + √b)^2

(III) x + y = a + 2 * √(a*b) + b

(IV)  Set:
x = a + b
y = 2 * √(a*b)

(V)  Determine  x - y:

x - y = a + -1*2 * √(a*b) + b  (see IV)
x - y = a - 2 * √(a*b) + b
√(x - y) = √a - √b

(VI)

√(x + y) * √(x - y) = (√a + √b) * (√a - √b)
√((x + y) * (x - y)) = (√a)^2 - (√b)^2
√(x^2 - y^2) = a - b


We have the following simultaneous equations set up:

(VII)
a + b = x     (from (IV))
a - b = √(x^2 - y^2)   (from (VI))

Solving the system in (VII) for both a and b yield:

(VIII)
a = x/2 + 1/2 * √(x^2 - y^2)
b = x/2 - 1/2 * √(x^2 - y^2)

Substituting a and b back in (I) and (II):

(IX)

√(x + y) = √(x/2 + 1/2 * √(x^2 - y^2)) + √(x/2 - 1/2 * √(x^2 - y^2))

√(x - y) = √(x/2 + 1/2 * √(x^2 - y^2)) - √(x/2 - 1/2 * √(x^2 - y^2))

Examples

Example 1:  Simplify  √(8 + 2 * √15)

x = 8
y = 2 * √15

x^2 - y^2
= 8^2 - (2 * √15)^2
= 64 -  4 * 15
= 4

Then: 

√(x/2 + 1/2 * √(x^2 - y^2))
= √(4 + 1/2 * √4)
= √(4 + 1/2 * 2)
= √5    // √a

And:

√(x/2 - 1/2 * √(x^2 - y^2))
= √(4 - 1/2 * √4)
= √(4 - 1/2 * 2)
= √3     // √b

Hence:

√(8 + 2 * √15) = √5 + √3

Example 2:  Simplify  √(88 + 2 * √567)

x = 88
y = 2 * √567

x^2 - y^2
= 88^2 - (2 * √567)^2
= 7744 - 2268
= 5476

Note √5476 = 74

Then: 

√(x/2 + 1/2 * √(x^2 - y^2))
= √(44 + 1/2 * 74)
= √81
= 9        // √a

And:

√(x/2 + 1/2 * √(x^2 - y^2))
= √(44  - 1/2 * 74)
= √7      // √b

√(88 + 2 * √567) = 9 + √7


Example 3:  Simplify √(19 - 4 * √22))  (note the subtraction)

x = 19
y = 4 * √22

x^2 - y^2
= 19^2 - (4 * √22)^2
= 9

√(x/2 + 1/2 * √(x^2 - y^2))  = √11
√(x/2 + 1/2 * √(x^2 - y^2))  = √8 = 2 * √2

Hence:

√(19 - 4 * √22))  = √11 - 2 * √2


Neat algebra.

Source:

Michael J. Wester, Editor.  Computer Algebra Systems: A Practical Guide John Wiley & Sons: Chichester 1999.  ISBN 978-0-471-983538


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.

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues

DM42 and HP 42S: Quadratic Equation, Characteristic Polynomial, and Eigenvalues The programs are listed for the Swiss Micros DM42 an...