module ProjectionMethods.Program

open Plotly.NET

let coordinateFunctionDimensions = [| 2; 3; 4; 5; 10; 15 |]

let ritzMethodSolutions = RitzMethod.getSolutions coordinateFunctionDimensions RitzTaskData.taskData

let collocationMethodSolutions = CollocationMethod.getSolutions coordinateFunctionDimensions CollocationTaskData.taskData

let x =
    let h = 2.0 / 1000.0
    Array.init 1001 (fun i -> -1.0 + float i * h)

let ritz_y_0 = x |> Array.map (fun x -> ritzMethodSolutions[0] x)

let mutable ritzChart = Chart.Line(x, ritz_y_0) |> Chart.withTraceInfo(Name = $"N = {coordinateFunctionDimensions[0]}")

let rec ritzMethodLoop i =
    if i = (coordinateFunctionDimensions |> Array.length)
    then
        ritzChart
        |> Chart.withXAxisStyle "X"
        |> Chart.withYAxisStyle "Y"
        |> Chart.withTitle "Решение методом Ритца"
        |> Chart.withLineStyle (Width = 2.0, Dash = StyleParam.DrawingStyle.Solid)
        |> Chart.show
    else
        let y = x |> Array.map (fun x -> ritzMethodSolutions[i] x)
        let line = Chart.Line(x, y) |> Chart.withTraceInfo(Name = $"N = {coordinateFunctionDimensions[i]}")
        ritzChart <- Chart.combine [ritzChart; line]
        ritzMethodLoop (i + 1) 

ritzMethodLoop 1
        
let collocation_y_0 = x |> Array.map (fun x -> collocationMethodSolutions[0] x)

let mutable collocationChart = Chart.Line(x, collocation_y_0) |> Chart.withTraceInfo(Name = $"N = {coordinateFunctionDimensions[0]}")

let rec collocationMethodLoop i =
    if i = (coordinateFunctionDimensions |> Array.length)
    then
        collocationChart
        |> Chart.withXAxisStyle "X"
        |> Chart.withYAxisStyle "Y"
        |> Chart.withTitle "Решение методом коллокации"
        |> Chart.withLineStyle (Width = 2.0, Dash = StyleParam.DrawingStyle.Solid)
        |> Chart.show
    else
        let y = x |> Array.map (fun x -> collocationMethodSolutions[i] x)
        let line = Chart.Line(x, y) |> Chart.withTraceInfo(Name = $"N = {coordinateFunctionDimensions[i]}")
        collocationChart <- Chart.combine [collocationChart; line]
        collocationMethodLoop (i + 1) 

collocationMethodLoop 1