ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 18 Feb 2024 22:37:31 +0100Imprecise nonlinear optimizationhttps://ask.sagemath.org/question/76071/imprecise-nonlinear-optimization/I want do do optimization to find the maximum of length of a vector under constraint of a polynomial in sagemath, but it output something strange. Is sagemath actually able to do such work?
#!/usr/bin/env sage
import sys
from sage.all import *
from scipy.optimize import NonlinearConstraint
# Assuming your vector is represented as a list or a vector in SageMath
x, y, z = var('x y z')
vector = [x, y, z]
# Define the optimization problem
initial_guess = [3, 3, 3]
def fun1(vector):
return -sum([v**2 for v in vector])
def fun2(x,y,z):
return x**2 + y**2 + z**2 -27
problemm = minimize(fun1, initial_guess, NonlinearConstraint(fun2,0,0))
print(problemm)
It gives output as below:
(600.1187424066786, 600.1187424066786, 600.1187424066786)Sun, 18 Feb 2024 22:37:31 +0100https://ask.sagemath.org/question/76071/imprecise-nonlinear-optimization/