# maximum of a two variable polynomial by fixing one of them

I have a Polynomial of two variables f(x,y) . I want to find the maximum of the function for a fixed value of y that depends on y and x changes on a closed interval. basically i want to find $Max f(x,b)$ : b$is a constant and$0 \leq x \leq 1$). Is there any way to do that in sage and the result be a function in y. edit retag close merge delete ## Comments 1 Please give us the polynomial$f$. If the question does not need$y$(or$b$) which is the question again without it? The function $$b\to\max_{0\le x\le 1} f(x,b)$$ should be found? (Or we can moreover set$b$to have a particular value, and also forget about this variable$b$... ?!) The polynomials are of the form$(1-x)^4 x (1-2bx+x^2)^2$and$(1-x)^2 x (1-2bx+x^2)$and i would like to find maximum of these polynomials with$0 \leq x \leq 1$, in terms of$b$or$(1-b)$what i know about b is that it is rational number close to 1 . ## 1 Answer Sort by » oldest newest most voted Warming up: First of all let us compute the maximum for some explicit values of$b$. Let's take the small list$0,1,1/2$. I need this as a final control later. Only for the function$f$with smaller degree in the sequel. The more complicated function may be attacked using a similar scheme. (But the higher degree...) var( 'x,b' ); f(x,b) = (1-x)^2 * x * ( 1 -2*b*x + x^2 ) for B in [ 0, 1, 1/2 ]: print "b =", B relList = [ xrel for xrel, mul in diff(f,x)(x,B).roots( ring=SR ) if xrel.n() in RR and 0 < xrel.n() and xrel.n() < 1 ] for xrel in relList: print ( "x* = %s\nf(x*,b) = %s with minpoly %s\n" % ( xrel.n(), f(xrel, B).n(), f(xrel,B).minpoly() ) )  This gives: b = 0 x* = 0.386488209564309 f(x*,b) = 0.167202635526186 with minpoly x^3 - 3408/3125*x^2 + 1248/3125*x - 128/3125 b = 1 x* = 0.200000000000000 f(x*,b) = 0.0819200000000000 with minpoly x - 256/3125 b = 1/2 x* = 0.297680702433558 f(x*,b) = 0.116134066923534 with minpoly x^3 - 1092/3125*x^2 + 188/3125*x - 12/3125  The general case now. Things become involved. Whatever we do, these results should be obtained as particular cases. Let us fix the mathematical notation and framework. Since$f(0,b)=f(1,b)=0$we expect a maximal value of the function$x\to f(x,b)$for$x$between zero and one. Let$x^*(b)$be the point where the maximum is reached, it is a root of$f'x$. An in this special case there is exactly one in$(0,1)$. The maximal value is$F(x^*(b),b)$. In order to get it, we have to eliminate$x$in the equations: $$f'_x(x,b) = 0\ ,$$ $$F = f(x,b)\ .$$ This may be done as follows. (Note that after some point$x.b$are no longer variables, but polynomial ring transcendental generators.) sage: var( 'x,b' ); sage: f(x,b) = (1-x)^2 * x * ( 1-2*b*x + x^2 ) sage: f (x, b) |--> -(2*b*x - x^2 - 1)*(x - 1)^2*x sage: diff( f, x ).factor() -(8*b*x^2 - 5*x^3 - 4*b*x + 3*x^2 - 3*x + 1)*(x - 1) sage: R.<x,b,F> = QQ[] sage: J = R.ideal( [ 8*b*x^2 - 5*x^3 - 4*b*x + 3*x^2 - 3*x + 1, F - f(x,b) ] ) sage: J.elimination_ideal(x) Ideal (1024*b^6*F + 8192*b^5*F^2 - 2560*b^5*F - 10240*b^4*F^2 - 128*b^5 - 512*b^4*F - 9280*b^3*F^2 + 384*b^4 + 4896*b^3*F + 13520*b^2*F^2 - 256*b^3 - 1888*b^2*F + 960*b*F^2 + 3125*F^3 - 256*b^2 - 2208*b*F - 3408*F^2 + 384*b + 1248*F - 128) of Multivariate Polynomial Ring in x, b, F over Rational Field sage: len( J.elimination_ideal(x).gens() ) 1 sage: G = J.elimination_ideal(x).gens()  (Ideal generator was manually rearranged.) The above$G$is morally the dependence we are searching for. The implicit function$F=F(b)$which solves$G(b,F(b))=0$is the searched function. So we only need to solve an equation of degree three in$F$for each value of$b$. We test this for the mentioned values$9$,$1$,$1/2\$. Well, i have to go back to variables. And i will use the poor man's copy paste via string and eval.

sG = str(G)
var( 'b,F' )
H(b,F) = eval( re.sub( '\^', '**', sG ) )
for B in (0, 1, 1/2):
print "b=%3s :: H(b,F) = %s" % ( B, H( B, F ).factor() )


This gives:

b=  0 :: H(b,F) = 3125*F^3 - 3408*F^2 + 1248*F - 128
b=  1 :: H(b,F) = (3125*F - 256)*F^2
b=1/2 :: H(b,F) = 3125*F^3 - 1092*F^2 + 188*F - 12


And we recognize the polynomials from the start.

An implicit plot of the implicit function may be obtained via:

sage: implicit_plot( H(b,F), (b,0,1), (F,0,0.2) )
Launched png viewer for Graphics object consisting of 1 graphics primitive

more