def test_solve_rosenbrock(self):
     """
     Minimize the Rosenbrock function using two separate least-squares
     terms.
     """
     for solver in solvers:
         #for grad in [True, False]:
         r = Rosenbrock()
         prob = LeastSquaresProblem(0, 1, opts_in=r)
         solver(prob)  # , grad=grad)
         self.assertAlmostEqual(prob.objective(), 0)
Ejemplo n.º 2
0
surf.fix('rc(0,0)')
surf.print_return_fn_names()

# Approach 1

prob1 = LeastSquaresProblem(opts_in=surf,
                            goals=[desired_area, desired_volume],
                            weights=[1, 1])
least_squares_serial_solve(prob1)

print("At the optimum using approach 1,")
print(" rc(m=1,n=0) = ", surf.get_rc(1, 0))
print(" zs(m=1,n=0) = ", surf.get_zs(1, 0))
print(" volume = ", surf.volume())
print(" area = ", surf.area())
print(" objective function = ", prob1.objective())
print(" -------------------------\n\n")


# Approach 2

surf2 = SurfaceRZFourier()
surf2.fix('rc(0,0)')
prob2 = LeastSquaresProblem(opts_in=surf2,
                            opt_return_fns=['area', 'volume'],
                            goals=[desired_area, desired_volume],
                            weights=[1, 1])
least_squares_serial_solve(prob2)
print("At the optimum using approach 2,")
print(" rc(m=1,n=0) = ", surf2.get_rc(1, 0))
print(" zs(m=1,n=0) = ", surf2.get_zs(1, 0))