Автор работы: Пользователь скрыл имя, 13 Марта 2013 в 07:49, контрольная работа
Задание № 1
Решить задачу линейного программирования с помощью симплекс-метода, построить двойственную задачу и определить ее решение:
F = 11x1+8x2+9x3+10x4 ® max
x1+2x2+3x3+2x4 £ 98
6x1+3x2+2x3+5x4 £ 500
3x1+4x2+5x3+2x4 £ 180
xj ³ 0, i=1,2,3,4.
Range("B14").Value = "Funkziya ne unimodal'na "
p = 1
End If
xp = tk
If ((f(x1 - (tk - t) * pk1, x2 - (tk - t) * pk2) > f(x1 - (tk) * pk1, x2 - (tk) * pk2)) And (f(x1 - (tk) * pk1, x2 - (tk) * pk2) > f(x1 - (tk + t) * pk1, x2 - (tk + t) * pk2))) Then
delta = t
a = tk
tk = tk + t
End If
If ((f(x1 - (tk - t) * pk1, x2 - (tk - t) * pk2) < f(x1 - (tk) * pk1, x2 - (tk) * pk2)) And (f(x1 - (tk) * pk1, x2 - (tk) * pk2) < f(x1 - (tk + t) * pk1, x2 - (tk + t) * pk2))) Then
delta = -t
b = tk
tk = tk - t
End If
While (p <> 1)
If ((f(x1 - (tk) * pk1, x2 - (tk) * pk2) < f(x1 - (xp) * pk1, x2 - (xp) * pk2)) And (delta * t > 0)) Then
a = xp
b = tk
p = 1
End If
If ((f(x1 - (tk) * pk1, x2 - (tk) * pk2) < f(x1 - (xp) * pk1, x2 - (xp) * pk2)) And (delta * t < 0)) Then
b = xp
a = tk
p = 1
End If
kk = kk + 1
xp = tk
tk = xp + (2 ^ kk) * delta
Wend
Do
' методом дихотомии находим tk
xk = ((a + b) / 2) - e
yk = ((a + b) / 2) + e
If (f(x1 - (yk) * pk1, x2 - (yk) * pk2) >= f(x1 - (xk) * pk1, x2 - (xk) * pk2)) Then b = yk
If (f(x1 - yk * pk1, x2 - yk * pk2) < f(x1 - xk * pk1, x2 - xk * pk2)) Then a = xk
ll = b - a
Loop Until l > ll
tk = (a + b) / 2
opt = tk
End Function
Sub MNS()
СтиркаЛист3
Dim eps1 As Double, eps2 As Double, M As Double, k As Double, tk As Double
Dim grx(2) As Double, x(2) As Double, xx(2) As Double
Dim xpr(2) As Double 'начальное приближение
xpr(0) = Range("A7").Value
xpr(1) = Range("B7").Value
q = 0
eps1 = Range("A9").Value
eps2 = Range("B9").Value
M = Range("C9").Value
x(0) = xpr(0)
x(1) = xpr(1)
Do
grx(0) = grad(x(0), x(1), 0)
grx(1) = grad(x(0), x(1), 1)
If ((((grx(0) * grx(0) + grx(1) * grx(1)) ^ 0.5) < eps1)) Then
xx(0) = x(0)
xx(1) = x(1)
q = 1
End If
If (k >= M) Then
xx(0) = x(0)
xx(1) = x(1)
q = 1
End If
If (q = 0) Then
tk = opt(grx(0), grx(1), x(0), x(1))
x(0) = x(0) - tk * grad(xpr(0), xpr(1), 0)
x(1) = x(1) - tk * grad(xpr(0), xpr(1), 1)
If ((((((x(0) - xpr(0)) * (x(0) - xpr(0)) + (x(1) - xpr(1)) * (x(1) - xpr(1))) ^ 0.5)) < eps2) And (Abs(f(x(0), x(1)) - f(xpr(0), xpr(1)))) < eps2) Then
xx(0) = x(0)
xx(1) = x(1)
q = 1
End If
xpr(0) = x(0)
xpr(1) = x(1)
End If
k = k + 1
Loop Until (q <> 0)
Range("A15").Value = "Ответ"
Range("C15").Value = "Итерация"
Range("D15").Value = "Z"
Range("A16").Value = xx(0)
Range("B16").Value = xx(1)
Range("C16").Value = k - 1
Range("D16").Value = f(xx(0), xx(1))
End Sub
Приложение 3
Function ff(x1 As Double, x2 As Double) As Double
ff = x1 ^ 2 + x2 ^ 2 - x1 * x2 - 3 / 4 * x2
End Function
Sub MNS4()
Dim minn As Double
Dim x1n As Double
Dim x2n As Double
Dim x1k As Double
Dim x2k As Double
Dim step1 As Double, step2 As Double
Dim tmpx1 As Double, tmpx2 As Double
Dim x1 As Double, x2 As Double
чистка4
x1n = 1 / 3
x2n = 1 / 3
x1k = 2 / 3
x2k = 2 / 3
step1 = (x1k - x1n) / 10
step2 = (x2k - x2n) / 10
x2 = x2n
minn = ff(1 / 3, 2 / 3)
For x1 = x1n To x1k Step step1
For x2 = x2n To x2k Step step2
If (ff(x1, x2) < minn) Then
minn = ff(x1, x2)
tmpx1 = x1
tmpx2 = x2
End If
Next x2
Next x1
Range("A31").Value = tmpx1
Range("B31").Value = tmpx2
Range("C31").Value = minn
End Sub
Информация о работе Контрольная работа по "Программированию и компьютерам"