aUCBLogo Demos and Tests / fit_t2
to fit_t2
xy=loadT2File "../temp/0x493K.t2
x=first xy
y=first butfirst xy
autoloadTest
end
to autoloadTest
setUpdateGraph "false
WindowMode
forever
[ clearScreen
;pr repcount
catch "error [ignore runResult [zzz]]
err=Error
if :err != []
[ clearText
print :err
waitMS 200
]
updategraph
updateVars
dispatchMessages
waitMS 100
if Key? [stop]
]
end
to zzz
; fit=f x
x2=rseq 25e-6 500e-6 count x
fit=f x2
fit2=g x2
clearScreen
line [[-400 -200][400 -200]] RGB 0 0 0
setpc 1
plot x fit
plot x y-fit
setpc 4
plot x y
setpc 2
plot2 x2 fit2
end
to f x
local [n a b y0 fy]
n=count x
x=(x/last x)*n
a=25e-6
b=500e-6
c=(ln b/a)/n
x=(exp x*c)*a
y0=3200
fy=(exp -((x*4250)^2.0))*y0
+(exp -((x*5800)^2.0))*y0*((sin x*21100*360-85)*0.335)
+80
; +(exp -((x*6000)^2.0))*1280*((sin x*21500*12*360-30)*0.023)
output fy
end
to g x
local [n a b y0 fy]
n=count x
; x=(x/last x)*n
a=25e-6
b=500e-6
c=(ln b/a)/n
; x=(exp x*c)*a
y0=3200
fy=(exp -((x*4350)^2.0))*y0
+(exp -((x*6000)^2.0))*y0*((sin x*21400*360-45)*0.33)
+80
; +(exp -((x*6000)^2.0))*1280*((sin x*21500*12*360-30)*0.023)
output fy
end
to lnseq a b n
local [i x]
i=rseq 1 n n
x=(exp i*(ln b/a)/n)*a
output x
end
to loadT2File fn
local [l lx ly]
lx=[]
ly=[]
openRead fn
setReader fn
ignore readWord
while [not eof?]
[ l=readList
lx=fput l.1 lx
ly=fput l.2 ly
]
setReader []
close fn
lx=reverse lx
ly=reverse ly
output List lx ly
end
to plot x y
xs=x/500*800-400
ys=y/5000*600-200
PenUp
setXY xs.1 ys.1
PenDown
setXY xs ys
end
to plot2 x y
xs=x*2000*800-400
ys=y/5000*600-200
PenUp
setXY xs.1 ys.1
PenDown
setXY xs ys
end