module GridMethod.Program

open Plotly.NET

let targetError = 1e-5
let initial_N = 10
let gridMethodResult = Algorithm.run TaskData.taskData initial_N targetError


let x =
    Array.init (10 * int (2.0 ** float (gridMethodResult.StepsCount - 1)) + 1) (fun i ->
        TaskData.taskData.InitialConditions.a
        + gridMethodResult.Step_h * 2.0 * float (i))

let y = gridMethodResult.Solution

Chart.Line(x, y)
|> Chart.withXAxisStyle ("X")
|> Chart.withYAxisStyle ("Y")
|> Chart.withTitle ("Приближенное решение (точность 10^(-5))")
|> Chart.withLineStyle (Width = 2.0, Dash = StyleParam.DrawingStyle.Solid)
|> Chart.show


let targetErrors = [ 1e-1; 1e-2; 1e-3; 1e-4; 1e-5 ]

let header = [ "Погрешность" ] @ List.map (fun x -> $"ε = {x}") targetErrors

let stepsRow title =
    let stepsList =
        Seq.init (targetErrors |> List.length) (fun i -> targetErrors[i] |> Algorithm.run TaskData.taskData initial_N)
        |> Seq.map (fun result -> $"{result.Step_h}")
        |> Seq.toList

    title :: stepsList

let rows = [ stepsRow "Интервал между точками (h)" ]

Chart.Table(header, rows) |> Chart.withSize (1000, 1500) |> Chart.show
