#Mathematical Functions
print "Enter - 1(1/x), 2(sqrtx),
3(sin), 4(cos), 5(tan),"
Print "6(expx), 7(lnx), 8(10**x),
9(log10x), 10(x**p)."
input k
print "Enter value to be evaluated ";: input x
if (k-1)=0 then goto k01
if (k-2)=0 then goto k02
if (k-3)=0 then goto k03
if (k-4)=0 then goto k04
if (k-5)=0 then goto k05
if (k-6)=0 then goto k06
if (k-7)=0 then goto k07
if (k-8)=0 then goto k08
if (k-9)=0 then goto k09
if (k-10)=0 then goto k10
k01:
y=1/x
print "1/x = ";:print y
goto Done
k02:
gosub sqrt
print "sqart = ";:print sqrtx
goto Done
k03:
#Convert degree
to radian
x=0.0174533*x
y=sin(x)
print "sinx = ";:print y
goto Done
k04:
#Convert degree
to radian
x=0.0174533*x
y=cos(x)
print "cosx = ";:print y
goto Done
k05:
#Convert degree
to radian
x=0.0174533*x
y=tan(x)
print "tanx = ";:print y
goto Done
k06:
gosub expe
print "expx = ";:print expx;:print " x 10**";:print k
goto Done
k07:
gosub log
print "logex = ";:print logx
goto Done
k08:
#Reduce input
number by 1/10**n, then multiply 10**n at the end
for j=0 to 1000
if x<1 then goto Endrun
x=x-1
next j
Endrun:
#Convert to
expanding variable in the series: x loge10=2.3025851*x
x=2.3025851*x
gosub expe
print "10**x = ";:print expx;:print
" x10**";:print (k+j)
goto Done
k09:
gosub log
#log10x=0.43429*logex
y=0.43429*logx
print "log10x = ";:print y
goto Done
k10:
print "Enter Value of the Exponental
= ";:input p
#y=x**p=expe(p*logex)
gosub xp
print "x**p = ";:print expx;:print
"x10**";:print k
goto Done
xp:
gosub log
x=p*logx
gosub expe
return
expe:
#Limit for input
is x=abs(78)
#expex=1 + x/1! + x**2/2! + ¡K +
x**n/n!
#Initialization
expx=1
xp=1
n=0
nf=1
delta=0.00000001
m=0
#Change sign if
x<0
x0=x
if x<0 then x=abs(x)
#Sum over series
SubLoop2:
m=m+1
exp0=expx
xp=xp*x
n=n+1
nf=nf*n
expx=expx+xp/nf
if abs(expx-exp0)<delta then goto
End2
if m>1000 then goto error
refresh
goto SubLoop2
End2:
#Move decimal
point to produce exponential representation: 1234=1.234*10**3
for k=0 to 1000
if expx<10 then goto Quit
expx=expx/10
next k
Quit:
#Reverse exp(x)
back to exp(-x) in case of x<0
if x0>0 then goto Finish
expx=1/expx
k=-k
Finish:
Return
log:
#For x>0, log10x=0.43429*logx
#Check number of
digits in the input
xint=int(x)
x$=string(xint)
L=length(x$)
logint=0
if L<1 then goto Cont1
if L=1 then goto Cont1
#If the number of digits > 1, then move the decimal point,
#for example:
loge1234=loge1.234+3*loge10=loge1.234+3*2.3025851
#This step is necessary since the expanding series converges
very slow for large x
logint=(L-1)*2.3025851
x0=x
xfrc=x
#Move the
decimal point
for k=1 to (L-1)
xfrc=xfrc/10
next k
x=xfrc
Cont1:
#Initialization
m=0
logx=0
n=1
x1=x-1
x1n=x1
x2=x+1
x2n=x2
x3=x1n/x2n
delta=0.00000001
#Sum over the
series: logex=2*[(x-1)/(x+1) + (x-1)**3/3*(x+1)**3
+ ¡K]
SubLoop:
logx=logx+x3
if abs(x3)<delta then goto Endlog
if m>1000 then goto error
n=n+2
x1n=x1n*x1*x1
x2n=x2n*x2*x2
x3=x1n/(n*x2n)
refresh
goto SubLoop
Endlog:
logx=2*logx
logx=logx+logint
return
sqrt:
#This method was developed by Heron of Alexandria in AD 60
#It starts with
an area A= 1*x, then varying the sides while keeping A constant,
#finally the
rectangle is reduced to a square: A=x=y*y, thus, sqrtx=y
#Initialization
A=x
xx=x
y=1
delta=0.00000001
#Algorithm to
produce a square
MainLoop:
xx=(xx+y)/2
#The following statement is for keeping the area constant
while varying y
y=A/xx
if abs(xx-y)<delta then goto Ende
goto MainLoop
Ende:
sqrtx=y
return
error:
print "Error ¡V out of computational range"
Done: