title: How to use pytorch to perform gradient descent, and print out the true minimum?
body: <p>I'm trying to use a gradient method to find a minimizer of a function <code>f</code>, where <code>x(k+1)=x(k)-α▽f(x)</code>, and <code>α=0.1</code>. The function <code>f</code> is <code>f(x) = 2*(x^3+1)^(-1/2)</code>, <code>x(0)=1</code>
  Here is the pytorch sample</p>
  <pre class="lang-py prettyprint-override"><code>import torch
  import torch.nn as nn
  from torch import optim
  
  alpha = 0.1
  
  class MyModel(nn.Module):
       def __init__(self):
            super().__init__()
            self.x = 1
  
  def forward(self, x):
       return 2*pow((pow(x,3)+1),(-1/2))
  
  model = MyModel()
  optimizer = optim.SGD(model.parameters(),lr=alpha)
  terminationCond = False
  
  while not terminationCond:
       f = model.forward(x)
       f.backward()
       optimizer.step()
       if x.grad &lt; 0.001:
             terminationCond = True
       optimizer.zero_grad()
  </code></pre>
  <p>But I cannot output the correct value of <code>x</code>, how to modify my code in order to find a minizer of a function <code>f</code>?</p>