- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocessor.lua
More file actions
Latest commit
47 lines (42 loc) · 1.53 KB
/
Copy pathprocessor.lua
File metadata and controls
47 lines (42 loc) · 1.53 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
-- data-processor, script for the processing of
-- experimental data
-- Copyright (C) 2015 Pavel Dolgov
--
-- See the LICENSE file for terms of use.
-- Calculate the distance using special formula.
-- cof argument is the coefficient of friction.
localfunctioncalculateDistance(height, angle, cof)
localexponent=math.exp(-2*angle*cof)
localcotangent=1/math.tan(angle)
localdistance=height*exponent*
(1/cof-cotangent)
returndistance
end
-- Calculate the distance using wrong formula.
-- (It's necessary to compare the experimental results with
-- results calculated by the wrong formula and results
-- calculated by the correct formula.)
-- cof argument is the coefficient of friction.
localfunctioncalculateDistanceWrongly(height, angle, cof)
localcotangent=1/math.tan(angle)
localdistance=height* (1/cof-cotangent)
returndistance
end
localout=io.open('results.txt', 'w')
localwrong_out=io.open('wrong_results.txt', 'w')
forlineinio.stdin:lines() do
localheight, sin, cof=
line:match('([%d.]+)%s([%d.]+)%s([%d.]+)')
if (height==nil) thenbreakend
height=tonumber(height)
sin=tonumber(sin)
cof=tonumber(cof)
localangle=math.asin(sin)
localdistance=calculateDistance(height, angle, cof)
localwrong_dist=calculateDistanceWrongly(height,
angle, cof)
out:write(tostring(distance), "\n")
wrong_out:write(tostring(wrong_dist), "\n")
end
out:close()
wrong_out:close()