Skip to content

Commit

Permalink
📒 feat(readme): Document work conclusions
Browse files Browse the repository at this point in the history
  • Loading branch information
worthant committed Nov 12, 2024
1 parent 7c1d52e commit 2afd1f9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 20 deletions.
39 changes: 31 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,24 @@
> Шаг дискретизации `s` - step
```bash
╭─boris at fedora in ⌁/dev/functional-programming-course/fp-lab3 (main↑1 ●2✚4…5)
╰─λ cat ./resources/large_input_data.csv | ./interpolation_cli -s 1.0 > ./resour
ces/large_output_data.md
╭─boris at fedora in ⌁/dev/functional-programming-course/fp-lab3 (main ✚5…2)
╰─λ cat ./resources/large_input_data.csv
| ./interpolation_cli -a linear,lagrange -s 1.0
> ./resources/large_output_data.md
```

### Ручной ввод

> Шаг дискретизации `s` - step
```bash
╭─boris at fedora in ⌁/dev/functional-programming-course/fp-lab3 (main↑1 ●2✚4…6)
╰─λ ./interpolation_cli -s 1.0 0 (0.409s) < 15:31:52
╭─boris at fedora in ⌁/dev/functional-programming-course/fp-lab3 (main ✚4…2)
╰─λ ./interpolation_cli -a linear,lagrange -s 1.0 130 (37.076s) < 14:21:11
0 0
1.571 1

Linear (going from point 0.0 with step 1.0, covering all input X (1.57 < 2.0)):
Linear (going from point 0.0 with step 1.0, covering all input X (1.57 < 2.0))
:
0.0 1.0 2.0
0.0 0.64 1.27

Expand All @@ -87,6 +89,25 @@ Linear (going from point 3.14 with step 1.0, covering all input X (4.71 < 5.14))
:
3.14 4.14 5.14
0.0 -0.64 -1.27


Lagrange (from point 0.0 with step 1.0, covering all input X (4.71 < 5.0))
:
0.0 1.0 2.0 3.0 4.0 5.0
0.0 0.97 0.84 0.12 -0.67 -1.03

12.568 0

Linear (going from point 4.71 with step 1.0, covering all input X (12.57 < 12.71))
:
4.71 5.71 6.71 7.71 8.71 9.71 10.71 11.71 12.71
-1.0 -0.87 -0.75 -0.62 -0.49 -0.36 -0.24 -0.11 0.02


Lagrange (from point 1.57 with step 1.0, covering all input X (12.57 < 12.57))
:
1.57 2.57 3.57 4.57 5.57 6.57 7.57 8.57 9.57 10.57 11.57 12.57
1.0 0.37 -0.28 -0.91 -1.49 -1.95 -2.26 -2.38 -2.25 -1.84 -1.11 0.0
```

<a id="arch"></a>
Expand Down Expand Up @@ -173,5 +194,7 @@ RabbitMQ и Kafka. Также интересна работа Супервизо
ген серверами, и в случае возникновения любого эксепшена не падает всё
приложение, а продолжает работу в штатном режиме. Стратегий супервизора не так
много и легко изучаются, язык прямо сделан для создания хорошей нагруженной
системы. В то же время, модули для работы с потоками I/O предоставляют
достаточно интуитивный и простой интерфейс для работы.
системы. Поигрался с обработкой сообщений и общением с супервизором. Модули для
работы с потоками I/O предоставляют достаточно интуитивный и простой интерфейс
для работы, поэтому было интересно и не слишком больно работать с потоковыми
режимами.
3 changes: 1 addition & 2 deletions lib/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ defmodule InterpolationCli.Application do
end

# Dummy function that does nothing but uses frequency
defp do_nothing_with_frequency(frequency) do
_unused_result = frequency * 1
defp do_nothing_with_frequency(_frequency) do
:ok
end
end
2 changes: 2 additions & 0 deletions lib/cli.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ defmodule InterpolationCli.CLI do
"""

def main(args) do
Process.flag(:trap_exit, true)

{options, _, _} =
OptionParser.parse(args,
switches: [algorithm: :string, frequency: :integer, step: :float],
Expand Down
19 changes: 10 additions & 9 deletions lib/lagrange_interpolator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,17 @@ defmodule InterpolationCli.LagrangeInterpolator do

defp lagrange_value(points, x) do
Enum.reduce(points, 0.0, fn {x_i, y_i}, acc ->
l_i =
Enum.reduce(points, 1.0, fn {x_j, _}, prod ->
if x_i != x_j do
prod * (x - x_j) / (x_i - x_j)
else
prod
end
end)
acc + y_i * basis_polynomial(points, x, x_i)
end)
end

acc + y_i * l_i
defp basis_polynomial(points, x, x_i) do
Enum.reduce(points, 1.0, fn {x_j, _}, prod ->
if x_i != x_j do
prod * (x - x_j) / (x_i - x_j)
else
prod
end
end)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/linear_interpolator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ defmodule InterpolationCli.LinearInterpolator do
end

# Linear interpolation
defp perform_linear_interpolation(points, step) do
def perform_linear_interpolation(points, step) do
[{x1, y1}, {x2, y2}] = points

xs = Stream.iterate(x1, &(&1 + step)) |> Enum.take_while(&(&1 <= x2 + step))
Expand Down

0 comments on commit 2afd1f9

Please sign in to comment.