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

МиАПР_ПОВТ_2012 / Васильков_Компьютерные технологии вычислений

.pdf
Скачиваний:
325
Добавлен:
31.05.2015
Размер:
3.92 Mб
Скачать

' Расчет погрешности

t r = Abs(tr - trl) / 3

' вывод

ActiveCell.OffsetO; 5) .FormulaRlCl = " Интеграл =" ActiveCell.Offset(9; 7).FormulaRlCl » trl

ActiveCell.OffsetdO; 5) .FormulaRlCl = _ " Погрешность <"

ActiveCell.OffsetdO; 7) .FormulaRlCl = tr ActiveCell.OffsetO; 5) .Range ("A1:D1") .Select Selection.BorderAround Weight:=xlMedium; _

Colorlndex:=xlAutomatic

Selection.Interior.Colorlndex = 4 Selection.Font.ColorIndex = 3

ActiveCell.Offsetd; 0) .Range("A1:D1") .Select Selection.BorderAround Weight:=xlMedium; _

Colorlndex:"xlAutomatic

Selection.Interior.Colorlndex = 4 Selection.Font.Colorlndex = 3 ActiveCell.Offset(-8; -5).RangeC'Al").Select

End Sub

Public Function GraficO Dim Xt As Double RangeC'Al") .Select

X0'="H6"

Xn » ActiveCell.Offset(5; 7).Value

Xk="H7"

Xk - ActiveCell.Offset(6; 7).Value

Nx=''H8"

Nx = ActiveCell.Offset(7; 7).Value

Xt - Xn i - 0

Hx - (Xk - Xn) / Nx sled - "K5:L" While Xt <- Xk

Yt - FuncI(Xt) RangeC'Al") .Select

ActiveCell.Offset(i + 4; 10).FormulaRlCl = Xt ActiveCell.Offsetd + 4'; 11) .FormulaRlCl = Yt Xt = Xt + Hx

i - i + 1

Wend

I_ - Str(i + 4)

I_ « Trim(I_) sled = sled + I_ ГрафикР (sled)

End Function

231

Sub GraficFO

Range("Al").Select

ActiveCell.OffsetO; 7) . FormulaRlCl = _

11 II

ActiveCell.OffsetdO; 7) . FormulaRlCl = _

 

It

II

 

 

 

ActiveSheet.ChartObj ects.Select

 

 

 

Selection.Delete

 

 

 

 

Grafic

 

 

 

 

 

End Sub

 

 

 

 

 

Sub Интеграл_исходнь1е_данные ()

 

 

 

Dim Xt As

Double

 

 

 

 

Dim Yt; Xn; Yn; Hx; Xk As Double

 

 

 

Range("Al").Select

 

= _

 

 

ActiveCell.Offset(0; 1).FormulaRlCl

 

f (х)"

"

Вычисление

интеграла от функции

ActiveCell.Offset(0; 1).Range("Al:El").Select

 

Selection.Font.Colorlndex = 3

= xlNone

 

Selection.Borders(xlLeft).LineStyle

 

Selection.Borders(xlRight).LineStyle

= xINone

 

Selection.Borders(xlTop).LineStyle = xINone

 

Selection.Borders(xlBottom).LineStyle = xINone

Selection.BorderAround

Weight:«xlMedium;

_

 

Colorlndex:«xlAutomatic

 

 

 

With Selection.Interior

 

 

 

.Colorlndex = 19

 

 

 

 

.Pattern « xlSolid

 

 

 

 

End With

 

 

 

 

 

Range("Al").Select

 

 

 

 

' Присвоение переменной К2 имени х

 

 

 

ActiveWorkbook.Names.Add Name:="x"; ^

 

 

RefersToRlCl:-"=R2Cll"

 

 

 

' Организация ввода исходных данных

 

 

 

inputfunc = Application. _

 

 

 

InputBox("Введите

функцию f(x)")

 

 

Xf - "-" & inputfunc

 

 

 

 

inputVal » Application. _

 

по X

- ХО")

InputBox("Введите

начало интервала

Xn » inputVal

 

 

 

 

inputVal = Application. _

 

 

Xk")

InputBox("Введите конечное значение по X -

Xk - inputVal

 

 

 

 

inputint

- Application. _

 

 

 

InputBox("Введите число шагов по X")

Nx » inputint

232

If NX < 1 Then NX = 10

 

If NX > 100 Then Nx = 100

 

Range ("Al").Select

 

 

. "04" = "f(x.y)"

6) .FormulaRlCl

•f(X)"

ActiveCell.OffsetO;

I "Р5"="Начальныеусловия"

 

ActiveCell.0ffset(4;

5).FormulaRlCl

 

"Граничные условия"

 

. «G6"="X0"

6).FormulaRlCl

- "XO"

ActiveCell.Offset(5;

ActiveCell.Offset(6; 6).FormulaRlCl = "XJc" ActiveCell.Offset(0; 10).FormulaRlCl = "X текущ." ActiveCell.Offset(2; 10).FormulaRlCl = "Функция f(x)

ActiveCell.Offset(3;

10).FormulaRlCl =

X"

ActiveCell.Offset(3;

11).FormulaRlCl =

f(x)"

ActiveCell.Offset{7;

5) .FormulaRlCl

= "Число шагов N

ActiveCell.Offset(9;

5).FormulaRlCl

»

 

ActiveCell.Offset(10; 5).FormulaRlCl =

 

ActiveCell.Offset(9;

7) .FormulaRlCl =

 

ActiveCell.Offset(10; 7).FormulaRlCl =

 

ActiveCell.Offset(0;

8) .Columns("A:A")

 

EntireColumn.ColumnWidth » 3,11

 

ActiveCell.Offset(2; 5).Range("A1:D10").Select

With Selection.Interior

 

 

.Colorlndex = 8

 

 

 

.Pattern = xlSolid

 

 

 

End With

 

 

 

ActiveCell.Offset(0; 0).Range("A1:D10").Select

Selection.Borders(xl^eft).LineStyle

« xlNone

 

Selection.Borders(xlRight).LineStyle

= xINone

Selection.Borders(xlTop).LineStyle " xINone

 

Selection.Borders(xlBottom).LineStyle = xINone

Selection.BorderAround Weight:=xlMedium; _

 

Colorlndex:=xlAutomatic

 

 

Selection.BorderAround Weight:=xlMedium; _

 

Colorlndex:=xlAutamatic

 

 

Range("Al").Select

7).Select

 

 

ActiveCell.Offset(3;

= xINone

 

Selection.Borders(xlLeft).LineStyle

 

Selection.Borders(xlRight).LineStyle

= xiNone

Selection.Borders(xlTop).LineStyle = xINone

Selection.Borders(xlBottom).LineStyle » xINone

Selection.BorderAround Weight:=xlMedium; _

Colorlndex:=xlAutomatic

ActiveCell.0ffset(2; 0).Select

Selection.Borders(xlLeft).LineStyle = xlNone

Selection.Borders(xlRight).LineStyle = xINone

Selection.Borders(xlTop).LineStyle = xINone

Selection.Borders(xlBottom).LineStyle = xINone

Selection.BorderAround Weight:=xlMedium; _

Colorlndex:=xlAutomatic

ActiveCell.0ffset(2; 0).Select

Selection.Borders(xlLeft).LineStyle = xINone

Selection.Borders(xlRight).LineStyle = xINone

Selection.Borders(xlTop).LineStyle = xINone

Selection.Borders(xlBottom).LineStyle = xINone

Selection.BorderAround Weight:=xlMedium; _

Colorlndex:«xlAutomatic

ActiveCell.Offset(-l; 0).Select

Selection.Borders(xlLeft).LineStyle = xINone

Selection.Borders(xlRight).LineStyle = xINone

Selection.Borders(xlTop).LineStyle «• xINone

Selection.Borders(xlBottom).LineStyle = xINone

Selection.BorderAround Weight:=xlMedium; _

Colorlndex:-xlAutomatic

With Selection.Borders(xlBottom)

.Weight = xlMedium

.Colorlndex = xlAutomatic

End With

Selection.BorderAround Weight:-xlMedium; _

Colorlndex:=xlAutomatic

 

 

ActiveCell.Offset(0; 0).Select

 

Selection.Interior.Colorlndex

= 2

 

ActiveCell.FormulaRlCl = Xk

 

 

ActiveCell.Offset(-l; 0).Select

 

Selection.Interior.ColorIndex

= 2

 

ActiveCell.FormulaRlCl = Xn

 

 

ActiveCell.0ffset(-2; 0).Select

 

Selection.Interior.Colorlndex

- 2

'

ActiveCell.FormulaRlCl = Xf

 

ActiveCell.0ffset(4; 0).Select

= 2

 

Selection.Interior.Colorlndex

 

ActiveCell.FormulaRlCl = Nx

 

 

ActiveSheet.Buttons. _

 

 

Add(17,4; 173,4; 102,2; 20,4).Select

Selection.OnAction = "Trap"

 

трапеций"

Selection.Characters.Text = "Метод

With Selection.Characters(Start:=l;

Length:=12).Font

.Name = "Arial Cyr"

 

 

.FontStyle = "Regular"

 

 

234

.Size - 10

.Strikethrough = False

.Superscript " False

.Subscript = False

.OutlineFont " False

.Shadow = False

.Underline - xlNone

.Colorlndex = xlAutomatlc

End With

ActiveSheet.Buttons. _

Add(120,4; 173,4; 102,2; 20,4).Select

Selection.OnAction = "Simp" Selection.Characters.Text - "Метод Симпсона"

With Selection.Characters(Start:=1; Length:=17).Font

.Name - "Arial Cyr"

.FontStyle = "Regular"

.Size - 10

.Strikethrough « False

.Superscript = False

.Subscript " False

.OutlineFont - False

.Shadow - False

.Underline « xINone

.Colorlndex = xlAutomatic End With

ActiveSheet.Buttons. _

Add(240; 173,4; 164,4; 20,4).Select Selection.OnAction = "GraficF" Selection.Characters.Text • _

"График после коррекции исх.дан."

With Selection.Characters(Start:-1; Length:=31).Font

.Name - "Arial Cyr"

.FontStyle - "Regular"

.Size " 10

.Strikethrough •= False

.Superscript " False .

.Subscript = False

.OutlineFont » False

.Shadow - False

.Underline = xINone

.Colorlndex = xlAutomatic

End With

Grafic End Sub

Ti

Модуль 4. Интерполяция

' Удаление тонки, на которую указывает курсор

Sub Удалить_точку() Dim X As Double

ActiveSheet.ChartObj ects.Select Selection.Delete ActiveSheet.Buttons.Select Selection.Delete

Ra « ActiveCell.Row

Co - ActiveCell.Column

Nx - ActiveCell.Offset(4 - Ra; 5 - Co).Value

If (Ra < 5) Or (Co > 2) Or ((Ra > 4 + Nx + D ) Then MsgBox ("Вы забыли указать удаляемую точку!");

vbOKOnly; "ВНИМАНИЕ!" GoTo Metka3

End If

If Co = 2 Then Col - -1 Else Col - 0 ActiveCell.Offset(5 - Ra + Nx + 1; Col + 2 ) . _

Range("Al").Select Selection.ClearContents Selection.Borders(xlLeft).LineStyle » xINone Selection.Borders(xlRight).LineStyle = xINone Selection.Borders(xlTop).LineStyle " xINone Selection.Borders(xlBottom).LineStyle •= xINone Selection.BorderAround LineStyle:«xlNone Selection.Interior.Colorlndex = xINone Range("Al").Select

For i - Ra To (5 + Nx + 2) ActiveCell.Offset(i - 1; 0).FormulaRlCl = _

ActiveCell.Offset(i; 0).Value ActiveCell.Offset(i - 1; 1).FormulaRlCl » _

ActiveCell.Offset(i; 1).Value

Next i

ActiveCell.Offset(5 + Nx; Col).Range("Al:CI").Select Selection.Borders(xlLeft).LineStyle » xINone Selection.Borders(xlRight).LineStyle " xINone Selection.Borders(xlTop).LineStyle " xINone Selection.Borders(xlBottom).LineStyle « xINone Selection.BorderAround LineStyle:=xlNone Selection.Interior.Colorlndex « xINone ActiveCell.Offset(-1; 0).Range("Al").Select Selection.BorderAround Weight:»xlMedium; _

Colorlndex:«xlAutomatic With Selection.Interior

.Colorlndex " 39

.Pattern " xlSolid End With

236

ActiveCell.Offset(0; 2) .RangeC'Al") .Select Selection.BorderAround Weight:=xlMedium; _

Colorlndex:=xlAutomatic

With Selection.Interior

.Colorlndex = 39

.Pattern " xlSolid End With

ActiveCell.Offset(0; -1).RangeC'Al").Select Selection.Borders(xlLeft).LineStyle •» xlNone Selection.Borders(xlRight).LineStyle " xINone Selection.Borders(xlTop).LineStyle " xINone

Selection.Borders(xlBottom).LineStyle = xINone Selection.BorderAround LineStyle:-xlNone

Selection.Interior.Colorlndex = xINone

GoTo Metka3 Met)ca3:

Range ("Al").Select

Nx = Nx - 1

ActiveCell.0ffset(3; 4).FormulaRlCl » Nx i •> 4 + Nx + 2

i_ - Str(i)

i_ « Trim(i_)

sledl - "A5:C" + i_ i_ - Str(Nx + 1) i_ « Trim(i_)

Range("Al").Select

sled = "»Lagrang_Qwik(R[-" S i_ S "]C[-2):RC[-1])" ActiveCell.0ffset(5 + Nx; 2).FormulaRlCl » sled Graphic (sledl)

Key

End Sub

'Вставка дополнительной точки перед той,

'на которую указывает курсор

Sub вставка_точки() Dim X As Double

ActiveSheet.ChartObj ects.Select Selection.Delete ActiveSheet.Buttons.Select Selection.Delete

Ra = ActiveCell.Row Co = ActiveCell.Column

Nx - ActiveCell.Offset(4 - Ra; 5 - Co).Value

If (Ra < 5) Or (Co > 2) Or ((Ra > 4 + Nx + 2)) Then MsgBox "Вы забыли указать место вставки " S _

"новой точки!"; _ vbOKOnly; "ВНИМАНИЕ!"

GoTo Metka3

237

End If

If Co - 2 Then Col - -1 Else Col = 0

ActiveCell.0ffset(5 - Ra + Nx + 1; Col + 2) . _

Range("Al").Select

Selection.ClearContents

Selection.Borders(xlLeft).LineStyle = xlNone

Selection.Borders(xlRight).LineStyle = xINone

Selection.Borders(xlTop).LineStyle = xINone

Selection.Borders(xlBottom).LineStyle » xINone

Selection.BorderAround LineStyle:"xlNone

Selection.Interior.Colorlndex « xINone

Range("Al").Select

ActiveCell.0ffset(4 + Nx + 2; 2).Range("Al").Select

Selection.BorderAround Weight:»xlMedium; _

Colorlndex:-xlAutomatic

With Selection.Interior

.Colorlndex - 39

.Pattern " xlSolid

End With

ActiveCell.Offset(0; -2).Range("Al").Select

Selection.BorderAround Weight:*xlMedium; _

Colorlndex:«xlAutomatic

With Selection.Interior

.Colorlndex - 39

.Pattern •» xlSolid

End With

ActiveCell.Offset(-l; 0).Range("Al").Select

Selection.BorderAround Weight:=xlMedium; _

Colorlndex: ««xlAutomatic

With Selection.Interior

.Colorlndex - 40

.Pattern » xlSolid

End With

ActiveCell.Offset(; 1) .Range("Al").Select

Selection.BorderAround Weight:"xlMedium; _

Colorlndex:=xlAutomatic

With Selection.Interior

.Colorlndex » 40

.Pattern " xlSolid

End With

' Сдвиг зяементов

Range("Al").Select

For i - 5 + Nx + 2 To Ra Step -1

ActiveCell.Offset(i; 0).FormulaRlCl =• _

ActiveCell.Offset(i - 1; 0).Value

ActiveCell.Offset(i; 1).FormulaRlCl = _

ActiveCell.Offset(i - 1; 1).Value

238

Next i

NX - NX + 1

ActiveCell.Offset(Ra - 1; 0).ClearContents

ActiveCell.Offset(Ra - 1; 1).ClearContents

' BeodXY

Metlca2:

inputVal >• Application.InputBox("Введите " 6 _

"значение аргумента X, больше предыдущего "

меньше последующего или для отмены " & _

"ввода ESC/Отмена")

~

If inputVal " False Then

 

 

Nx - NX - 1

+ 2)

 

For i - Ra To (5 + Nx

- _

ActiveCell.Offsetd

- 1; 0) .FormulaRlCl

ActiveCell.Offsetd; 0) .Value

 

ActiveCell.Offset(i - 1; 1).FormulaRlCl - _ ActiveCell.Offsetd; 1) .Value

Next i

ActiveCell.0ffset(5 + Nx + 1; Col),

Range("A1:C1").Select Selection.Borders(xlLeft).LineStyle - xINone Selection.Borders(xlRight).LineStyle « xiNone Selection.Borders(xlTop).LineStyle « xINone Selection.Borders(xlBottom).LineStyle « xINone Selection.BorderAround LineStyle:-xINone Selection.Interior.ColorIndex « xINone ActiveCell.0ff3et(-l; 0).Range("Al").Select Selection.BorderAround Weight:-xlMedium; _

Color Index :-xlAutonnatic With Selection.Interior

•ColorIndex " 3 9

.Pattern • xlSolid End With

ActiveCell.Offset(0; 2).Range("Al").Select Selection.BorderAround Weight:-xlMedium; _

Colorlndex:-xlAutomatic With Selection.Interior

.Colorlndex - 39

.Pattern - xlSolid • End With

ActiveCell.Offset(0; -1).Range("Al").Select Selection.Borders(xlLeft).LineStyle » xINone Selection.Borders(xlRight).LineStyle - xINone Selection.Borders(xlTop).LineStyle - xINone Selection.Borders(xlBottom).LineStyle - xINone Selection.BorderAround LineStyle:-xINone Selection.Interior.Colorlndex - xlNone

G O T O Metka3

End If

ActiveCell.OffsetO; 4) .FormulaRlCl = Nx X - inputVal

If Ra = 5 Then

If (ActiveCell.Offset(Ra; 0).Value <= X) Then MsgBox "Значения X надо вводить " & _

"по возрастанию. Введите другое " S _ "значение, меньше первого"; _ vbOKOnly; "ВНИМАНИЕ!"

GoTo Metka2 End If

End If

If Ra > 5 And Ra < 5 + Nx Then

If (ActiveCell.Offset(Ra; 0).Value <= X) Then MsgBox "Значения X надо вводить " & _

"по возрастанию. Введите другое " S _ "значение, меньше следующего"; _ VbOKOnly; "ВНИМАНИЕ!"

GoTo Metka2 End If

If (ActiveCell.Offset(Ra - 2; 0).Value >= X) Then MsgBox "Значения X надо вводить " S _

"по возрастанию. Введите другое " & _ "значение, больше предыдущего"; _

VbOKOnly;

"ВНИМАНИЕ!"

GoTo Metka2

'

End If

End If

If Ra = 5 + Nx Then

If (ActiveCell.Offset(Ra - 2; 0).Value >= X) Then

MsgBox "Значения X надо вводить " & _

"по возрастанию. Введите другое " & _

"значение, больше предыдущего"; _

VbOKOnly; "ВНИМАНИЕ!"

GoTo Metka2

End If

End If

If inputVal <> False Then

Metkal:

inputVall = Application. _

InputBox("Введите значение Функции Y")

Range("Al").Select

ActiveCell.Offset(Ra; 0).Range("Al:B1").Select

Selection.BorderAround Weight:=xlMedium; _

Colorlndex:-xlAutomatic

ActiveCell.Offset(0; 1).Range("Al").Select

240