Option Strict On
Imports System.IO
Module Module1
    Dim A As Double = 1
    Dim k_1 As Double = 0.05
    Dim k_2 As Double = 0.0065
    Function diff(ByVal t As Double, ByVal P As Double) As Double
        Return k_1 * A * Math.Exp(-k_1 * t) - k_2 * P
    End Function
    Sub Main()
        Dim P As Double = 0
        Dim t As Double = 0
        Dim dt As Double = 10
        Dim tmax As Double = 500
        Dim writer As New StreamWriter("output.csv")
        writer.WriteLine(" Расчет методом Эйлера кинетики хим. реакции")
        writer.WriteLine()
        writer.WriteLine(" Начальное значение t; {0}", t)
        writer.WriteLine(" Начальное значение P; {0}", P)
        writer.WriteLine(" Конечное значение t; {0}", tmax)
        writer.WriteLine(" Шаг интегрирования; {0}", dt)
        writer.WriteLine()
        writer.WriteLine("      t; [P]")
        For i As Integer = 0 To CInt(tmax / dt)
            writer.WriteLine("    {0}; {1}", t, P)
            P = P + dt * diff(t, P)
            t = t + dt
        Next i
        writer.Close()

        Console.WriteLine(" Расчет методом Эйлера кинетики хим. реакции")
        Console.WriteLine()
        Console.WriteLine(" Начальное значение t; {0}", t)
        Console.WriteLine(" Начальное значение P; {0}", P)
        Console.WriteLine(" Конечное значение t; {0}", tmax)
        Console.WriteLine(" Шаг интегрирования; {0}", dt)
        Console.WriteLine()
        Console.WriteLine("      t; [P]")
        For u As Integer = 0 To CInt(tmax / dt)
            Console.WriteLine("    {0}; {1}", t, P)
            P = P + dt * diff(t, P)
            t += dt
        Next u
        Console.ReadLine()
    End Sub

End Module
