# Exploiting the results of an optimization

The code bellow work perfectly but if i get ride of show(), it doesn't display in LaTeX secondly I would like to display not Simply show(x1) but "x=show(x1)". How can I do that ?

(The question continue after the code)

%display latex
var('A, x, y, l, alpha, beta, R, p_x, p_y');
U= A*x^(alpha)*y^(beta);
show(U)
D = p_x*x + p_y*y;
show(D)
show(U)
solve(D==R, y)
L = U-l*(D-R)
show(L)
L_x= L.diff(x)
show(L_x)
L_y= L.diff(y)
show(L_y)
L_l= L.diff(l)
%display latex
var('A, x, y, l, alpha, beta, R, p_x, p_y');
U= A*x^(alpha)*y^(beta);
show(U)
D = p_x*x + p_y*y;
show(D)
show(U)
solve(D==R, y)
L = U-l*(D-R)
show(L)
L_x= L.diff(x)
show(L_x)
L_y= L.diff(y)
show(L_y)
L_l= L.diff(l)
show(L_l)
z=solve([L_x==0, L_y==0, L_l==0,], x, y, l)
show(z)
x1=z.right()
show(x1)
y1=z.right()
show(y1)
show(l1)
show(U1)
latex(U1)


Now yesterday some one shows me how to do the same thing with a dictionary

z=solve([L_x==0, L_y==0, L_l==0,], x, y, l, solution_dict=True)
show(z)


how can I extact $x= solution$ and so on.

edit retag close merge delete

Sort by » oldest newest most voted

If you put %display latex you do not have to write show(D), simply write D and start a new cell.

Regarding your second question, you can do:

SR.var("x") == x1


and it will look like what you want if you have %display latex

Regarding your last question, you can get the value of x in the first (actually the only one) solution of z by typing z[x]

more