Задача 9(2) (Программы 3)
Описание файла
Файл "Задача 9(2)" внутри архива находится в папке "Программы 3". Документ из архива "Программы 3", который расположен в категории "". Всё это находится в предмете "практика расчётов на пэвм" из 2 семестр, которые можно найти в файловом архиве МГУ им. Ломоносова. Не смотря на прямую связь этого архива с МГУ им. Ломоносова, его также можно найти и в других разделах. .
Онлайн просмотр документа "Задача 9(2)"
Текст из документа "Задача 9(2)"
Option Strict On
Imports System.IO
Module Module1
Sub Main()
Dim E As Double
Dim n As Integer
Dim rdr As StreamReader = New StreamReader("data.txt")
n = Integer.Parse(rdr.ReadLine())
Dim t(n - 1, 0) As Double
Dim Cp(n - 1, 0) As Double
Console.WindowWidth = 95
Console.BackgroundColor = ConsoleColor.White
Console.Clear()
Console.ForegroundColor = ConsoleColor.DarkBlue
For i As Integer = 0 To n - 1
Dim row As String = rdr.ReadLine
Dim p As Integer = row.IndexOf("/")
t(i, 0) = Double.Parse(row.Substring(0, p)) * 10 ^ (-3)
Cp(i, 0) = Double.Parse(row.Substring(p + 1))
Next
Dim vector_T(4, 0) As Double
For i As Integer = 0 To 4
For k As Integer = 0 To n - 1
If i = 4 Then
E = E + (t(k, 0) ^ (-2)) * Cp(k, 0)
Else
E = E + (t(k, 0) ^ (i)) * Cp(k, 0)
End If
Next
vector_T(i, 0) = E
E = 0
Next
Dim matrix_U(4, 4) As Double
For i As Integer = 0 To 4
For j As Integer = 0 To 4
For k As Integer = 0 To n - 1
If i = 4 And j = 4 Then
E = E + (t(k, 0) ^ (-2)) * (t(k, 0) ^ (-2))
Else
If i = 4 Then
E = E + (t(k, 0) ^ (-2)) * (t(k, 0) ^ j)
Else
If j = 4 Then
E = E + (t(k, 0) ^ i) * (t(k, 0) ^ (-2))
Else
E = E + (t(k, 0) ^ i) * (t(k, 0) ^ j)
End If
End If
End If
Next
matrix_U(i, j) = E
E = 0
Next j
Next i
Dim solution(4, 0) As Double
Dim s As Jama.Matrix = New Jama.Matrix(solution)
Dim u As Jama.Matrix = New Jama.Matrix(matrix_U)
Dim tv As Jama.Matrix = New Jama.Matrix(vector_T)
s = u.solve(tv)
Dim A As Double = s(0, 0)
Dim B As Double = s(1, 0)
Dim C As Double = s(2, 0)
Dim D As Double = s(3, 0)
Dim F As Double = s(4, 0)
Console.WriteLine()
Console.WriteLine(" Формула аппроксимирующей функции:")
Console.WriteLine()
Console.ForegroundColor = ConsoleColor.DarkGreen
Console.WriteLine(" Cp = ({0:F5}) + ({1:F5}) * t + ({2:F5}) * t^2 + ({3:F5}) * t^3 + ({4:F5}) * t^(-2)", A, B, C, D, F)
Console.ForegroundColor = ConsoleColor.DarkBlue
Console.WriteLine("_____________________________________________________________________________________________")
Console.WriteLine()
Console.ForegroundColor = ConsoleColor.DarkGreen
Console.WriteLine(" i t(i) Cp(i) по формуле разность")
Console.ForegroundColor = ConsoleColor.DarkBlue
Console.WriteLine()
Dim file As StreamWriter
file = New StreamWriter("results.csv")
For i As Integer = 0 To n - 1
Dim M As Double = A + B * t(i, 0) + C * t(i, 0) ^ 2 + D * t(i, 0) ^ 3 + F * t(i, 0) ^ (-2)
Console.WriteLine(" {0,2} {1,10:F2} {2,10:F4} {3,10:F4} {4,10:F4}", i, t(i, 0) * 1000, Cp(i, 0), M, Cp(i, 0) - M)
file.WriteLine("{0}; {1}; {2}", t(i, 0) * 1000, Cp(i, 0), M)
Next
file.Close()
Console.ForegroundColor = ConsoleColor.DarkGreen
Console.WriteLine()
Console.WriteLine(" Для выхода нажмите enter")
Console.ReadLine()
End Sub
End Module