Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Otchet_po_2_labe_VBA

.docx
Скачиваний:
46
Добавлен:
29.03.2015
Размер:
734.68 Кб
Скачать

Отчёт по лабораторной работе № 2

Вариант №34

Выполнил Борисов Е.С. гр. АСУ-11

Тема: Организация итеративных (рекуррентных) вычислений с использованием операторов повторения (циклов).

Задача: Разработать алгоритм и программу вычисления координат каждой критической точки, полученной в результате пересечения объектов, участвующих в формировании закрашенных областей рисунка варианта.

Код на языке VBA:

Function f(x As Double) As Double

f = (Sqr(26 ^ 2 - (x + 4.07703720636856) ^ 2) - 2 - 14.56541) / -0.98905

End Function

Function f1(x As Double) As Double

f1 = (Sqr(1 - ((x - 16.4833556090187) / 22) ^ 2) * 13 + 6 - 14.56541) / -0.98905

End Function

Function f2(x As Double) As Double

f2 = Sqr(26 ^ 2 - (x + 4.07703720636856) ^ 2) - 2

End Function

Function krug(x As Double) As Double

krug = Sqr(26 ^ 2 - (x + 4.07703720636856) ^ 2) - 2

End Function

Function line(x As Double) As Double

line = -0.98905 * x + 14.56541

End Function

Function iter() As Double

Dim eps As Double, x As Double, x0 As Double

eps = 0.001

x0 = 0

x = f(x0)

Do

x0 = x

x = f(x0)

Loop Until Abs(x - x0) < eps

iter = x

End Function

Function scan() As Double

Dim x As Double, a As Double, b As Double

Dim h As Double, y As Double, y1 As Double

a = -5

b = 5

h = 0.001

x = a

Do

y = f1(x)

y1 = f1(x + h)

If y * y1 < 0 Then

scan = y

End If

x = x + h

Loop Until x > b

End Function

Function scan2() As Double

Dim x As Double, a As Double, b As Double

Dim h As Double, y As Double, y1 As Double

Dim e As Double

x = 10

h = 0.05

e = 0.001

p = 25

Do While Abs(h) > e

If f2(x) * f2(x + h) < 0 Then

x = x + h

h = -h / p

End If

x = x + h

Loop

scan2 = x

End Function

Function srav(x As Double, y As Double) As Boolean

Dim R As Double, a1 As Double, b1 As Double

Dim x1 As Double, y1 As Double, x0 As Double, y0 As Double

Dim b As Double, k As Double, t As Double

Const pi = 3.141593

a1 = 22

b1 = 13

R = 26

y0 = -28 + R ' коэфицент y0 у окружности

x0 = Sqr(26 ^ 2 - (0 - y0) ^ 2) - 30 ' коэфицент x0 у окружности

k = Tan((135.315384 * pi) / 180) ' коэфицент k у прямой

b = -6.657 - k * Sqr(26 ^ 2 - (-6.657 - y0) ^ 2) + x0 ' коэфицент b у прямой

y1 = -7 + b1 ' коэфицент y0 у эллипса

x1 = -(Sqr(1 - ((0 - y1) / b1) ^ 2) * a1 - 36) ' коэфицент x0 у эллипса

t = ((((36 - x1) / a1) ^ 2 + ((0 - y1) / b1) ^ 2)) 't равно 1 для точности сравнения с уравнением эллипса

If (((x - x0) ^ 2 + (y - y0) ^ 2 <= R ^ 2 + 0.1) And (y <= k * x + b) And y >= 0 And x <= 0 And (((x - x1) / a1) ^ 2 + ((y - y1) / b1) ^ 2) >= t) Then

srav = True

Else

If (((x - x0) ^ 2 + (y - y0) ^ 2 >= R ^ 2) And (y >= k * x + b) And y >= 0 And x > 0 And ((((x - x1) / a1) ^ 2 + ((y - y1) / b1) ^ 2)) <= t) Then

srav = False

Else

srav = False

End If

End If

End Function

Sub find_p()

Dim x As Double, y As Double, x1 As Double, y1 As Double, x2 As Double, y2 As Double

Dim flag As Boolean

flag = True

Do While flag

x = iter()

y = krug(x)

flag = srav(x, y)

Loop

flag = True

Do While flag

x1 = scan()

y1 = line(x1)

flag = srav(x1, y1)

Loop

flag = True

Do While flag

x2 = scan2()

y2 = krug(x2)

flag = srav(x2, y2)

Loop

ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=5, NumColumns:=6

With ActiveDocument.Tables.Item(1)

.Cell(1, 1).Range.Text = "Найменование"

.Cell(2, 1).Range.Text = "точки"

.Cell(3, 1).Range.Text = "P1"

.Cell(4, 1).Range.Text = "P2"

.Cell(5, 1).Range.Text = "P3"

.Cell(1, 2).Range.Text = "Аналитический"

.Cell(1, 3).Range.Text = "расчет"

.Cell(1, 4).Range.Text = "Вычислительный"

.Cell(1, 5).Range.Text = ""

.Cell(1, 6).Range.Text = "метод"

.Cell(2, 2).Range.Text = "X"

.Cell(2, 3).Range.Text = "Y"

.Cell(2, 4).Range.Text = "X"

.Cell(2, 5).Range.Text = "Y"

.Cell(2, 6).Range.Text = "*"

.Cell(3, 2).Range.Text = -9.0531

.Cell(3, 3).Range.Text = 23.5194

.Cell(3, 4).Range.Text = x

.Cell(3, 5).Range.Text = y

.Cell(3, 6).Range.Text = "A"

.Cell(4, 2).Range.Text = 0.0267795

.Cell(4, 3).Range.Text = 14.5919

.Cell(4, 4).Range.Text = x1

.Cell(4, 5).Range.Text = y1

.Cell(4, 6).Range.Text = "B"

.Cell(5, 2).Range.Text = 21.92296

.Cell(5, 3).Range.Text = 0

.Cell(5, 4).Range.Text = x2

.Cell(5, 5).Range.Text = y2

.Cell(5, 6).Range.Text = "C"

End With

End Sub

Sub Lab2()

find_p

End Sub

Результаты тестирования

Найменование

Аналитический

расчет

Вычислительный

метод

точки

X

Y

X

Y

*

P1

-9,0531

23.5194

-9,053053400

23,51938993

A

P2

0,0267795

14,5919

5,824237E-04

14,56483395

B

P3

21,92296

0

21,8440800

2,377932E-02

C

Алгоритм решения

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]