Code: Select all
print ""
print ""
print " Calibration v.1.0"
print ". by 'Lauderdale'"
print ""
varr = 1
button "c" text "touch to continue" at 10,450 size 300,50
while varr = 1
if button_pressed ("c")=1 then varr = 2
end while
button "c" delete
refresh
print ""
print "First you will input the data points (x,y). After, the program outputs linear and exp fits with r^2."
varr = 2
button "d" text "touch to start" at 10,450 size 300,50
while varr = 2
if button_pressed ("d")=1 then varr = 3
end while
button "d" delete
input "# of data points ":data
totaly = 0
totallny = 0
totalxsq = 0
totalxy = 0
totalxlny = 0
totalx = 0
if data < 5 then
print ""
print ""
print ""
print "Sorry but you need nore data points"
goto end
endif
dim points(data,2)
for k = 0 to data-1
j = k+1
input "x"&j&"":xx
points(k,0) = xx
input "y"&j&"":yy
points(k,1) = yy
lnyy = ln(yy)
totaly = totaly + yy
totallny = totallny + lnyy
totalxsq = totalxsq + xx^2
totalx = totalx + xx
totalxy = totalxy + xx*yy
totalxlny = totalxlny + xx*lnyy
next k
a = (data*totalxy - (totalx*totaly))/(data*totalxsq - (totalx)^2)
b = (totaly - a*totalx)/data
p = (data*totalxlny - totalx*totallny)/(data*totalxsq - totalx^2)
q = (totallny - p*totalx)/data
avrg = totaly/j
ssa = 0
ssb = 0
ssp = 0
ssq = 0
for m = 0 to data-1
ssa = (points(m,1)-avrg)^2 + ssa
ssb = ((a*points(m,0)+b)-points(m,1))^2 + ssb
ssp = (points(m,1)-avrg)^2 + ssp
ssq = (exp(p*points(m,0)+q)-points(m,1))^2 + ssq
next m
print ""
print "y = ax + b"
print "a = "&a&""
print "b = "&b&""
if ssa = 0 then
print ""
print ""
print "ambiguous result, r^2 may be 1."
else
rsq = 1 - (ssb/ssa)
rsqln = 1 - (ssq/ssp)
print ""
print "r^2 = "&rsq&""
print ""
print "y = p*q^x"
p = exp(p)
q = exp(q)
print "p = "&p&""
print "q = "&q&""
print ""
print "r^2 = "&rsqln&""
endif
end: