-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path121.bas
More file actions
138 lines (126 loc) · 1.94 KB
/
Copy path121.bas
File metadata and controls
138 lines (126 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
'rem Data Peak Finder
rem Adapted for SMALLBASIC by CARSTEN
rem Original from
rem www3.sympatico.ca/ltoms/html/peak_finder.html
label loop
cls
print
print "Data Peak Finder Using Least Squares"
print " equally spaced points"
print
REM enter data
dim y(100)
dim z(100)
rem data entry
input "Number of points to input? ";n
label dleap
input "Use keyboard (k) or read from data (d)? ";c$
if c$="k" then
for i=1 to n
print "y(";i;")= ";
input " ";y1
y(i)=y1
next i
end if
if c$="d" then
for i=1 to n
read y1
y(i)=y1
next i
end if
if c$<>"d" and c$<>"k" then goto dleap
rem mode of operation
print "Chose mode:"
print " 1. Absolute max and min. "
print " 2. Calculated max and min."
print " 3. Quit."
print
label again
input "(1,2,3) ";q
if q=1 then gosub absolute
if q=2 then gosub relative
if q=3 then end
gosub again
print
rem absolute min and max
label absolute
a=y(3)
b=y(3)
j=3
k=3
for r=3 to n-2
if a> y(r) then
goto aleap
else
a=y(r)
j=r
end if
goto bleap
label aleap
if y(r)> b then
goto bleap
else
b=y(r)
k=r
end if
label bleap
next r
gosub fit
gosub prin
return
rem find deriative
label relative
for k=3 to n-2
z(k)=y(k+1)-y(k-1)+2*(y(k+2)-y(k-2))
z(k)=z(k)/10
next k
z(1)=z(3)
z(2)=z(3)
z(n)=z(n-2)
z(n-1)=z(n)
rem find zeros
for k=4 to n-2
t=z(k)*z(k-1)
if t>= 0 then goto rleap
j=k
gosub fit
u=x
j=k-1
gosub fit
if abs(x)< abs(u) then goto sleap
j=k
gosub fit
label sleap
gosub prin
label rleap
next k
return
rem calculate coefficients of parabolic fit
label fit
c=17*y(j)+12*(y(j-1)+y(j+1))-3*(y(j-2)+y(j+2))
c=c/35
d=y(j+1)-y(j-1)+2*(y(j+2)-y(j-2))
d=d/10
e=2*(y(j-2)-y(j)+y(j+2))-y(j-1)-y(j+1)
e=e/7
if e=0 then goto mleap
x=-1*d/e
p=c+(d+e*x/2)*x
b$="Max= "
if e< 0 then goto nleap
b$="Min= "
goto nleap
label mleap
b$="Indeterminate "
x=0
p=0
label nleap
return
label prin
print
print b$;p;" at x= ";j+x
print
return
data 84,85,83,105,108,123,107,96,102,92
data 111,93,102,76,78,64,64,61,54,51
end'