Option Strict On
Imports System.IO
Module Module1

    Function f(ByVal x As Double) As Double
        Return -2 * (1 - Math.Exp(-x)) * Math.Exp(-x)
    End Function
    Sub Main()
        Const OutputFile As String = "output.csv"
        Dim output As StreamWriter
        output = New StreamWriter(OutputFile)
        Dim t, t0, tk, h, xprev, x, uprev, u, per As Double
        Dim isChanged, isDef As Boolean
        t0 = 0 : tk = 30 : h = 0.001
        xprev = 2 : uprev = 0 : u = 0
        isChanged = False
        per = 0
        isDef = False
        For I As Integer = 1 To CInt((tk - t0) / h)
            t = t0 + I * h
            x = xprev + h * u
            u = uprev + h * f(x)
            If u > 0 Then isChanged = True
            If u < 0 And (isChanged) And (Not (isDef)) Then
                per = t
                isChanged = False
                isDef = True
                Console.WriteLine("Период {0} с", per)
            End If
            xprev = x : uprev = u
            output.WriteLine("{0:F3};{1};{2}", t, xprev, uprev)
        Next I
        output.Close()
        Console.ReadLine()
        End
Sub

End Module

