二次函数求最小值

import tensorflow as tf


x = tf.constant(3.0)
y = tf.constant(2.0)
r = tf.constant(.1)
while True:
    with tf.GradientTape(persistent=False) as tape:
        tape.watch([x, y])
        y = 5 * x ** 2 - 3 * x + 10
        dy = tape.gradient(y, x)
        x -= dy * r
        print(dy, x, y)

你可能感兴趣的:(二次函数求最小值)