84 lines
1.1 KiB
Python
84 lines
1.1 KiB
Python
# %%
|
|
from IPython.display import display
|
|
from sympy import Matrix, symbols
|
|
|
|
[a, b] = symbols("x_1, x_2")
|
|
x0 = Matrix([1.1, 0.9])
|
|
print("x0:")
|
|
display(x0)
|
|
|
|
f = Matrix(
|
|
[
|
|
[20.0 - (18.0 * a) - 2.0 * (b ** 2.0)],
|
|
[(-4.0 * b) * (a - (b ** 2.0))]
|
|
])
|
|
|
|
Df = Matrix(
|
|
[
|
|
[-18.0, -4.0 * b],
|
|
[-4.0 * b, (-4.0 * a) + 12.0 * (b ** 2.0)]
|
|
])
|
|
|
|
Df0 = Df.subs(
|
|
{
|
|
a: x0[0],
|
|
b: x0[1]
|
|
})
|
|
|
|
|
|
f0 = f.subs(
|
|
{
|
|
a: x0[0],
|
|
b: x0[1]
|
|
})
|
|
|
|
print("Df(x0):")
|
|
display(Df0)
|
|
print("f(x0):")
|
|
display(f0)
|
|
print("||f(x0)||_2")
|
|
display(f0.norm(2))
|
|
|
|
d0 = Df0.solve(-f0)
|
|
|
|
print("d0")
|
|
display(d0)
|
|
print("||d0||_2")
|
|
display(d0.norm(2))
|
|
|
|
x1 = x0 + d0
|
|
print("x1:")
|
|
display(x1)
|
|
|
|
Df1 = Df.subs(
|
|
{
|
|
a: x1[0],
|
|
b: x1[1]
|
|
})
|
|
|
|
f1 = f.subs(
|
|
{
|
|
a: x1[0],
|
|
b: x1[1]
|
|
})
|
|
|
|
print("Df(x1)")
|
|
display(Df1)
|
|
print("f(x1)")
|
|
display(f1)
|
|
print("||f(x1)||_2")
|
|
display(f1.norm(2))
|
|
|
|
d1 = Df1.solve(-f1)
|
|
|
|
print("d1")
|
|
display(d1)
|
|
print("||d1||_2")
|
|
display(d1.norm(2))
|
|
|
|
x2 = x1 + d1
|
|
|
|
print("x2")
|
|
display(x2)
|
|
|
|
# %%
|