-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocessor.lua
More file actions
47 lines (42 loc) · 1.53 KB
/
processor.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.
local function calculateDistance(height, angle, cof)
local exponent = math.exp(-2 * angle * cof)
local cotangent = 1 / math.tan(angle)
local distance = height * exponent *
(1 / cof - cotangent)
return distance
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.
local function calculateDistanceWrongly(height, angle, cof)
local cotangent = 1 / math.tan(angle)
local distance = height * (1 / cof - cotangent)
return distance
end
local out = io.open('results.txt', 'w')
local wrong_out = io.open('wrong_results.txt', 'w')
for line in io.stdin:lines() do
local height, sin, cof =
line:match('([%d.]+)%s([%d.]+)%s([%d.]+)')
if (height == nil) then break end
height = tonumber(height)
sin = tonumber(sin)
cof = tonumber(cof)
local angle = math.asin(sin)
local distance = calculateDistance(height, angle, cof)
local wrong_dist = calculateDistanceWrongly(height,
angle, cof)
out:write(tostring(distance), "\n")
wrong_out:write(tostring(wrong_dist), "\n")
end
out:close()
wrong_out:close()