import%20marimo%0A%0A__generated_with%20%3D%20%220.15.2%22%0Aapp%20%3D%20marimo.App()%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22!%5BMOSEK%20ApS%5D(https%3A%2F%2Fwww.mosek.com%2Fstatic%2Fimages%2Fbranding%2Fwebgraphmoseklogocolor.png%20)%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20Optimization%20problem%20over%20nonnegative%20trigonometric%20polynomials.%20%23%0A%0A%20%20%20%20We%20consider%20the%20trigonometric%20polynomial%0A%0A%20%20%20%20%24%24H(%5Comega)%20%3D%20x_0%20%2B%202%20%5Csum_%7Bk%3D1%7D%5En%20%5B%20%5CRe(x_k)%20%5Ccos(%5Comega%20k)%20%2B%20%5CIm(x_k)%20%5Csin(%5Comega%20k)%20%5D%2C%24%24%0A%0A%20%20%20%20where%20%24H(%5Comega)%24%20is%20a%20real%20valued%20function%20paramtrized%20by%20the%20complex%20vector%20%24x%5Cin%20%7B%5Cbf%20C%7D%5E%7Bn%2B1%7D%24%2C%20and%20where%20%24%5CIm(x_0)%3D0%24.%0A%0A%20%20%20%20The%20example%20shows%20how%20to%20construct%20a%20*non-negative*%20polynomial%20%24H(%5Comega)%5Cgeq%200%2C%20%5C%3A%20%5Cforall%20%5Comega%24%20that%20satisfies%2C%0A%0A%20%20%20%20%24%241%20-%20%5Cdelta%20%5Cleq%20%20H(%5Comega)%20%5Cleq%201%20%2B%20%5Cdelta%2C%20%5Cquad%20%20%5Cforall%20%5Comega%20%5Cin%20%5B0%2C%20%5Comega_p%5D%24%24%0A%0A%20%20%20%20while%20minimizing%20%24%5Csup_%7B%5Comega%5Cin%20%5B%5Comega_s%2C%5Cpi%5D%7D%20H(%5Comega)%24%20over%20the%20variables%20%24x%24.%0A%0A%20%20%20%20In%20the%20signal%20processing%20literature%20such%20a%20trigonometric%20polynomial%20is%20known%20as%20(the%20squared%20amplitude%20response%20of)%20a%20Chebyshev%20lowpass%20filter.%20%0A%0A%20%20%20%20A%20squared%20amplitude%20response%20%24H(%5Comega)%24%20is%20always%20symmetric%20around%20%240%24%2C%20so%20%24%5CIm(x_k)%3D0%24%2C%20and%20we%20consider%20only%0A%0A%20%20%20%20%24%24H(%5Comega)%20%3D%20x_0%20%2B%202%20%5Csum_%7Bk%3D1%7D%5En%20x_k%20%5Ccos(%5Comega%20k)%20%24%24%0A%0A%20%20%20%20over%20the%20real%20vector%20%24x%5Cin%20%7B%5Cbf%20R%7D%5E%7Bn%2B1%7D%24.%20However%2C%20the%20concepts%20in%20the%20example%20are%20readily%20applied%20to%20the%20case%20with%20%24x%5Cin%20%7B%5Cbf%20C%7D%5E%7Bn%2B1%7D%24.%0A%0A%20%20%20%20References%3A%0A%20%20%20%20%20%201.%20%22Squared%20Functional%20Systems%20and%20Optimization%20Problems%22%2C%20%20Y.%20Nesterov%2C%202004.%0A%0A%20%20%20%20%20%202.%20%22Convex%20Optimization%20of%20Non-negative%20Polynomials%3A%20Structured%20Algorithms%20and%20Applications%22%2C%20Ph.D%20thesis%2C%20Y.%20Hachez%2C%202003.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20mosek%0A%20%20%20%20from%20%20%20mosek.fusion%20import%20Model%2C%20Domain%2C%20Expr%2C%20ObjectiveSense%2C%20Matrix%2C%20Var%0A%20%20%20%20import%20mosek.fusion.pythonic%0A%20%20%20%20from%20%20%20math%20import%20cos%2C%20pi%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20sys%0A%20%20%20%20return%20Domain%2C%20Expr%2C%20Matrix%2C%20Model%2C%20ObjectiveSense%2C%20Var%2C%20cos%2C%20np%2C%20pi%2C%20sys%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%23%20Nonnegativity%20everywhere%20%23%23%23%0A%0A%20%20%20%20Nesterov%20proved%20in%20%5B1%5D%20that%20%24H(%5Comega)%20%5Cgeq%200%2C%20%5C%3A%20%5Cforall%20%5Comega%24%20if%20and%20only%20if%20%0A%20%20%20%20%24%24x_i%20%3D%20%5Clangle%20T_i%5E%7Bn%2B1%7D%2C%20X%20%5Crangle%2C%20%5Cquad%20X%20%5Cin%20%7B%5Cmathcal%20H%7D%5E%7Bn%2B1%7D_%2B%2C%24%24%0A%20%20%20%20where%20%24%7B%5Cmathcal%20H%7D_%2B%24%20is%20the%20cone%20of%20Hermitian%20semidefinite%20matrices%20and%20%24T_i%24%20is%20a%20Toeplitz%20matrix%0A%20%20%20%20%24%24%5BT_i%5D_%7Bkl%7D%20%3D%20%5Cleft%20%5C%7B%20%5Cbegin%7Barray%7D%7Bll%7D1%2C%20%26%20k-l%3Di%5C%5C0%20%26%20%5Ctext%7Botherwise%7D.%5Cend%7Barray%7D%20%5Cright%20.%24%24%0A%20%20%20%20For%20example%2C%20for%20%24n%3D2%24%20we%20have%0A%20%20%20%20%24%24%0A%20%20%20%20%20%20%20T_0%20%3D%20%5Cleft%5B%5Cbegin%7Barray%7D%7Bccc%7D%0A%20%20%20%20%20%20%201%20%26%200%20%26%200%5C%5C0%20%26%201%20%26%200%5C%5C0%20%26%200%20%26%201%0A%20%20%20%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%20%20%20%5Cright%5D%2C%20%5Cquad%0A%20%20%20%20%20%20%20T_1%20%3D%20%5Cleft%5B%5Cbegin%7Barray%7D%7Bccc%7D%0A%20%20%20%20%20%20%200%20%26%200%20%26%200%5C%5C1%20%26%200%20%26%200%5C%5C0%20%26%201%20%26%200%0A%20%20%20%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%20%20%20%5Cright%5D%2C%0A%20%20%20%20%20%20%20%5Cquad%0A%20%20%20%20%20%20%20T_2%20%3D%20%5Cleft%5B%5Cbegin%7Barray%7D%7Bccc%7D%0A%20%20%20%20%20%20%200%20%26%200%20%26%200%5C%5C0%20%26%200%20%26%200%5C%5C1%20%26%200%20%26%200%0A%20%20%20%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%20%20%20%5Cright%5D.%0A%20%20%20%20%24%24%0A%20%20%20%20In%20our%20case%20we%20have%20%24%5CIm(x_i)%3D0%24%2C%20i.e.%2C%20%24X%5Cin%20%7B%5Cmathcal%20S%7D%5E%7Bn%2B1%7D_%2B%24%20is%20a%20real%20symmetric%20semidefinite%20matrix.%0A%0A%20%20%20%20We%20define%20the%20*cone%20on%20nonnegative%20trigonometric%20polynomials*%20as%0A%20%20%20%20%24%24%0A%20%20%20%20%20%20%20K%5En_%7B0%2C%5Cpi%7D%20%3D%20%5C%7B%20x%5Cin%20%5Cmathbf%7BR%7D%20%5Ctimes%20%5Cmathbf%7BC%7D%5En%20%5Cmid%20x_i%20%3D%20%5Clangle%20X%2C%20T_i%5Crangle%2C%20%5C%3A%20i%3D0%2C%5Cdots%2Cn%2C%20%5C%3A%20X%5Cin%5Cmathcal%7BH%7D_%2B%5E%7Bn%2B1%7D%20%5C%7D.%0A%20%20%20%20%24%24%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Expr%2C%20Matrix)%3A%0A%20%20%20%20def%20T_dot_X(n%2C%20i%2C%20X%2C%20a%3D1.0)%3A%0A%20%20%20%20%20%20%20%20if%20i%3E%3Dn%20or%20i%3C%3D-n%3A%20return%20Expr.constTerm(0.0)%0A%20%20%20%20%20%20%20%20else%3A%20return%20Expr.dot(Matrix.diag(n%2C%20a%2C%20-i)%2C%20X)%0A%20%20%20%20return%20(T_dot_X%2C)%0A%0A%0A%40app.cell%0Adef%20_(Domain%2C%20T_dot_X)%3A%0A%20%20%20%20def%20trigpoly_0_pi(M%2C%20x)%3A%0A%20%20%20%20%20%20%20%20'''x%5Bi%5D%20%3D%3D%20%3CT(n%2B1%2Ci)%2CX%3E'''%0A%20%20%20%20%20%20%20%20n%20%3D%20int(x.getSize()-1)%0A%20%20%20%20%20%20%20%20X%20%3D%20M.variable(%22X%22%2C%20Domain.inPSDCone(n%2B1))%0A%0A%20%20%20%20%20%20%20%20for%20i%20in%20range(n%2B1)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20M.constraint(T_dot_X(n%2B1%2Ci%2CX)%20%3D%3D%20x%5Bi%5D)%0A%20%20%20%20return%20(trigpoly_0_pi%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Note%20that%20we%20have%20dropped%20the%20imaginary%20part%20of%20%24X%24.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%23%20Nonnegativity%20on%20%24%5B0%2Ca%5D%24%20%23%23%23%0A%0A%20%20%20%20Similarly%2C%20%24H(%5Comega)%24%20is%20nonnegative%20on%20%24%5B0%2Ca%5D%24%20if%20and%20only%20if%0A%0A%20%20%20%20%24%24x_i%20%3D%0A%20%20%20%20%5Clangle%20X_1%2C%20T_i%5E%7Bn%2B1%7D%20%5Crangle%20%2B%20%0A%20%20%20%20%5Clangle%20X_2%2C%20T_%7Bi%2B1%7D%5En%20%5Crangle%20%2B%0A%20%20%20%20%5Clangle%20X_2%2C%20T_%7Bi-1%7D%5En%20%5Crangle%20-%0A%20%20%20%202%20%5Ccos(a)%5Clangle%20X_2%2C%20T_%7Bi%7D%5En%20%5Crangle%2C%20%5Cquad%20%0A%20%20%20%20X_1%20%5Cin%20%7B%5Cmathcal%20H%7D%5E%7Bn%2B1%7D_%2B%2C%20%5C%3A%0A%20%20%20%20X_2%20%5Cin%20%7B%5Cmathcal%20H%7D%5En_%2B%2C%0A%20%20%20%20%24%24%0A%20%20%20%20or%20equivalently%0A%20%20%20%20%24%24%0A%20%20%20%20%20%20K%5En_%7B0%2Ca%7D%20%3D%20%5C%7B%20x%5Cin%20%5Cmathbf%7BR%7D%5Ctimes%20%5Cmathbf%7BC%7D%5En%20%5Cmid%0A%20%20%20%20%20%20%20x_i%20%3D%20%5Clangle%20X_1%2C%20T_i%5E%7Bn%2B1%7D%20%5Crangle%20%2B%0A%20%20%20%20%20%20%20%5Clangle%20X_2%20%2C%20T_%7Bi%2B1%7D%5En%20%5Crangle%20%2B%0A%20%20%20%20%20%20%20%5Clangle%20X_2%20%2C%20T_%7Bi-1%7D%5En%20%5Crangle%20-%0A%20%20%20%20%20%20%202%5Ccos(a)%5Clangle%20X_2%20%2C%20T_i%5En%5Crangle%2C%20%5C%3A%20X_1%5Cin%20%5Cmathcal%7BH%7D_%2B%5E%7Bn%2B1%7D%2C%20X_2%5Cin%5Cmathcal%7BH%7D_%2B%5En%20%5C%7D.%0A%20%20%20%20%24%24%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Domain%2C%20T_dot_X%2C%20cos)%3A%0A%20%20%20%20def%20trigpoly_0_a(M%2C%20x%2C%20a)%3A%0A%20%20%20%20%20%20%20%20'''x%5Bi%5D%20%3D%3D%20%3CT(n%2B1%2Ci)%2CX1%3E%20%2B%20%3CT(n%2Ci%2B1)%2CX2%3E%20%2B%20%3CT(n%2Ci-1)%2CX2%3E%20-%202*cos(a)*%3CT(n%2Ci)%2CX2%3E'''%0A%20%20%20%20%20%20%20%20n%20%3D%20int(x.getSize()-1)%0A%20%20%20%20%20%20%20%20X1%20%3D%20M.variable(Domain.inPSDCone(n%2B1))%0A%20%20%20%20%20%20%20%20X2%20%3D%20M.variable(Domain.inPSDCone(n))%0A%0A%20%20%20%20%20%20%20%20for%20i%20in%20range(n%2B1)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20M.constraint(T_dot_X(n%2B1%2Ci%2CX1)%20%2B%20T_dot_X(n%2Ci%2B1%2CX2)%20%2B%20%5C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20T_dot_X(n%2Ci-1%2CX2)%20%2B%20T_dot_X(n%2Ci%2CX2%2C-2*cos(a))%20%3D%3D%20x%5Bi%5D)%0A%20%20%20%20return%20(trigpoly_0_a%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Note%20that%20we%20have%20dropped%20the%20imaginary%20part%20of%20%24X_1%24%20and%20%24X_2%24.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%23%20Nonnegativity%20on%20%24%5Ba%2C%5Cpi%5D%24%20%23%23%23%0A%0A%20%20%20%20Finally%2C%20%24H(%5Comega)%24%20is%20nonnegative%20on%20%24%5Ba%2C%5Cpi%5D%24%20if%20and%20only%20if%0A%0A%20%20%20%20%24%24x_i%20%3D%20%0A%20%20%20%20%5Clangle%20X_1%2C%20T_i%5E%7Bn%2B1%7D%20%5Crangle%20-%0A%20%20%20%20%5Clangle%20X_2%2C%20T_%7Bi%2B1%7D%5En%20%5Crangle%20-%0A%20%20%20%20%5Clangle%20X_2%2C%20T_%7Bi-1%7D%5En%20%5Crangle%20%2B%0A%20%20%20%202%20%5Ccos(a)%5Clangle%20X_2%2C%20T_%7Bi%7D%5En%20%5Crangle%2C%20%5Cquad%20%0A%20%20%20%20X_1%20%5Cin%20%7B%5Cmathcal%20S%7D%5E%7Bn%2B1%7D_%2B%2C%20%5C%3A%0A%20%20%20%20X_2%20%5Cin%20%7B%5Cmathcal%20S%7D%5En_%2B%2C%0A%20%20%20%20%24%24%0A%20%20%20%20or%20equivalently%0A%20%20%20%20%24%24%0A%20%20%20%20%20%20K%5En_%7Ba%2C%5Cpi%7D%20%3D%20%5C%7B%20x%5Cin%20%5Cmathbf%7BR%7D%5Ctimes%20%5Cmathbf%7BC%7D%5En%20%5Cmid%0A%20%20%20%20%20%20%20x_i%20%3D%20%5Clangle%20X_1%2C%20T_i%5E%7Bn%2B1%7D%20%5Crangle%20-%0A%20%20%20%20%20%20%20%5Clangle%20X_2%20%2C%20T_%7Bi%2B1%7D%5En%20%5Crangle%20-%0A%20%20%20%20%20%20%20%5Clangle%20X_2%20%2C%20T_%7Bi-1%7D%5En%20%5Crangle%20%2B%0A%20%20%20%20%20%20%202%5Ccos(a)%5Clangle%20X_2%20%2C%20T_i%5En%5Crangle%2C%20%5C%3A%20X_1%5Cin%20%5Cmathcal%7BH%7D_%2B%5E%7Bn%2B1%7D%2C%20X_2%5Cin%5Cmathcal%7BH%7D_%2B%5En%20%5C%7D.%0A%20%20%20%20%24%24%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Domain%2C%20T_dot_X%2C%20cos)%3A%0A%20%20%20%20def%20trigpoly_a_pi(M%2C%20x%2C%20a)%3A%0A%20%20%20%20%20%20%20%20'''x%5Bi%5D%20%3D%3D%20%3CT(n%2B1%2Ci)%2CX1%3E%20-%20%3CT(n%2Ci%2B1)%2CX2%3E%20-%20%3CT(n%2Ci-1)%2CX2%3E%20%2B%202*cos(a)*%3CT(n%2Ci)%2CX2%3E'''%0A%20%20%20%20%20%20%20%20n%20%3D%20int(x.getSize()-1)%0A%20%20%20%20%20%20%20%20X1%20%3D%20M.variable(Domain.inPSDCone(n%2B1))%0A%20%20%20%20%20%20%20%20X2%20%3D%20M.variable(Domain.inPSDCone(n))%0A%0A%20%20%20%20%20%20%20%20for%20i%20in%20range(n%2B1)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20M.constraint(T_dot_X(n%2B1%2Ci%2CX1)%20%2B%20T_dot_X(n%2Ci%2B1%2CX2%2C-1.0)%20%2B%20%5C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20T_dot_X(n%2Ci-1%2CX2%2C-1.0)%20%2B%20T_dot_X(n%2Ci%2CX2%2C2*cos(a))%20%3D%3D%20x%5Bi%5D)%0A%20%20%20%20return%20(trigpoly_a_pi%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22Note%20that%20we%20have%20dropped%20the%20imaginary%20part%20of%20%24X_1%24%20and%20%24X_2%24.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%20An%20epigraph%20formulation%20%23%23%0A%20%20%20%20The%20*epigraph*%20%24H(%5Comega)%20%5Cleq%20t%24%20can%20now%20be%20characterized%20simply%20as%20%0A%20%20%20%20%24-u%20%5Cin%20K%5En_%7B%5Ba%2Cb%5D%7D%2C%20%5C%3A%20u%3D(x_0-t%2C%20%5C%2C%20x_%7B1%3An%7D).%24%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Domain%2C%20pi%2C%20trigpoly_0_a%2C%20trigpoly_0_pi%2C%20trigpoly_a_pi)%3A%0A%20%20%20%20def%20epigraph(M%2C%20x%2C%20t%2C%20a%2C%20b)%3A%0A%20%20%20%20%20%20%20%20'''Models%200%20%3C%3D%20H(w)%20%3C%3D%20t%2C%20for%20all%20w%20in%20%5Ba%2C%20b%5D%2C%20where%0A%20%20%20%20%20%20%20%20%20%20%20%20%20H(w)%20%3D%20x0%20%2B%202*x1*cos(w)%20%2B%202*x2*cos(2*w)%20%2B%20...%20%2B%202*xn*cos(n*w)'''%0A%20%20%20%20%20%20%20%20n%20%20%3D%20int(x.getSize()-1)%20%20%20%20%0A%20%20%20%20%20%20%20%20u%20%3D%20M.variable(n%2B1%2C%20Domain.unbounded())%0A%20%20%20%20%20%20%20%20M.constraint(t%20%3D%3D%20x%5B0%5D%20%2B%20u%5B0%5D)%20%0A%20%20%20%20%20%20%20%20M.constraint(x%5B1%3A%5D%20%2B%20u%5B1%3A%5D%20%3D%3D%200)%0A%0A%20%20%20%20%20%20%20%20if%20a%3D%3D0.0%20and%20b%3D%3Dpi%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20trigpoly_0_pi(M%2C%20u)%0A%20%20%20%20%20%20%20%20elif%20a%3D%3D0.0%20and%20b%3Cpi%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20trigpoly_0_a(M%2C%20u%2C%20b)%0A%20%20%20%20%20%20%20%20elif%20a%3Cpi%20and%20b%3D%3Dpi%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20trigpoly_a_pi(M%2C%20u%2C%20a)%0A%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(%22invalid%20interval.%22)%0A%20%20%20%20return%20(epigraph%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%20A%20hypograph%20formulation%20%23%23%0A%20%20%20%20Similarly%2C%20the%20*hypograph*%20%24H(%5Comega)%20%5Cgeq%20t%24%20can%20be%20characterized%20as%20%0A%20%20%20%20%24u%20%5Cin%20K%5En_%7B%5Ba%2Cb%5D%7D%2C%20%5C%3A%20u%3D(x_0-t%2C%20%5C%2C%20x_%7B1%3An%7D).%24%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Domain%2C%20Var%2C%20pi%2C%20trigpoly_0_a%2C%20trigpoly_0_pi%2C%20trigpoly_a_pi)%3A%0A%20%20%20%20def%20hypograph(M%2C%20x%2C%20t%2C%20a%2C%20b)%3A%0A%20%20%20%20%20%20%20%20'''Models%200%20%3C%3D%20t%20%3C%3D%20H(w)%2C%20for%20all%20w%20in%20%5Ba%2C%20b%5D%2C%20where%0A%20%20%20%20%20%20%20%20%20%20%20%20%20H(w)%20%3D%20x0%20%2B%202*x1*cos(w)%20%2B%202*x2*cos(2*w)%20%2B%20...%20%2B%202*xn*cos(n*w)'''%0A%0A%20%20%20%20%20%20%20%20n%20%20%3D%20int(x.getSize()-1)%20%20%20%20%0A%20%20%20%20%20%20%20%20u0%20%3D%20M.variable(1%2C%20Domain.unbounded())%20%20%20%20%0A%20%20%20%20%20%20%20%20M.constraint(t%20%3D%3D%20x%5B0%5D%20-%20u0)%0A%20%20%20%20%20%20%20%20u%20%3D%20Var.vstack(%20u0%2C%20x%5B1%3A%5D%20)%0A%0A%20%20%20%20%20%20%20%20if%20a%3D%3D0.0%20and%20b%3D%3Dpi%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20trigpoly_0_pi(M%2C%20u)%0A%20%20%20%20%20%20%20%20elif%20a%3D%3D0.0%20and%20b%3Cpi%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20trigpoly_0_a(M%2C%20u%2C%20%20b)%0A%20%20%20%20%20%20%20%20elif%20a%3Cpi%20and%20b%3D%3Dpi%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20trigpoly_a_pi(M%2C%20u%2C%20a)%0A%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(%22invalid%20interval.%22)%0A%20%20%20%20return%20(hypograph%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%20Putting%20it%20together%20%23%23%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Domain%2C%20Model)%3A%0A%20%20%20%20n%20%3D%2010%0A%20%20%20%20M%20%3D%20Model(%22trigpoly%22)%0A%20%20%20%20x%20%3D%20M.variable(%22x%22%2C%20n%2B1%2C%20Domain.unbounded())%0A%20%20%20%20return%20M%2C%20x%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Global%20nonnegativity%20%23%23%23%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(M%2C%20trigpoly_0_pi%2C%20x)%3A%0A%20%20%20%20%23%20H(w)%20%3E%3D%200%0A%20%20%20%20trigpoly_0_pi(M%2C%20x)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Passband%20specifications%20%23%23%23%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(M%2C%20epigraph%2C%20hypograph%2C%20pi%2C%20x)%3A%0A%20%20%20%20wp%20%3D%20pi%2F4%0A%20%20%20%20delta%20%3D%200.05%0A%0A%20%20%20%20%23%20H(w)%20%3C%3D%20(1%2Bdelta)%2C%20w%20in%20%5B0%2C%20wp%5D%20%20%20%20%0A%20%20%20%20epigraph(M%2C%20x%2C%201.0%2Bdelta%2C%200.0%2C%20wp)%0A%0A%20%20%20%20%23%20(1-delta)%20%3C%3D%20H(w)%2C%20w%20in%20%5B0%2C%20wp%5D%0A%20%20%20%20hypograph(M%2C%20x%2C%201.0-delta%2C%200.0%2C%20wp)%0A%20%20%20%20return%20(wp%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Stopband%20specifications%20%23%23%23%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Domain%2C%20M%2C%20epigraph%2C%20pi%2C%20wp%2C%20x)%3A%0A%20%20%20%20ws%20%3D%20wp%20%2B%20pi%2F8%0A%0A%20%20%20%20%23%20H(w)%20%3C%20t%2C%20w%20in%20%5Bws%2C%20pi%5D%0A%20%20%20%20t%20%3D%20M.variable(%22t%22%2C%201%2C%20Domain.greaterThan(0.0))%0A%20%20%20%20epigraph(M%2C%20x%2C%20t%2C%20ws%2C%20pi)%0A%20%20%20%20return%20(t%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Setting%20the%20objective%20%23%23%23%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(M%2C%20ObjectiveSense%2C%20t)%3A%0A%20%20%20%20M.objective(ObjectiveSense.Minimize%2C%20t)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(M%2C%20sys)%3A%0A%20%20%20%20M.setLogHandler(sys.stdout)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(M)%3A%0A%20%20%20%20M.solve()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(x)%3A%0A%20%20%20%20x.level()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(t)%3A%0A%20%20%20%20t.level()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20Plotting%20the%20amplitude%20response%20%23%23%23%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(cos%2C%20np%2C%20pi%2C%20x)%3A%0A%20%20%20%20xx%20%3D%20x.level()%0A%20%20%20%20def%20H(w)%3A%20return%20xx%5B0%5D%20%2B%202*sum(%5Bxx%5Bi%5D*cos(i*w)%20for%20i%20in%20range(1%2Clen(xx))%5D)%0A%20%20%20%20w%20%20%3D%20np.linspace(0%2C%20pi%2C%20100)%0A%20%20%20%20%23%20'%25matplotlib%20inline'%20command%20supported%20automatically%20in%20marimo%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20plt.plot(w%2C%20%5BH(wi)%20for%20wi%20in%20w%5D%2C%20'k')%0A%20%20%20%20plt.show()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%3Ca%20rel%3D%22license%22%20href%3D%22http%3A%2F%2Fcreativecommons.org%2Flicenses%2Fby%2F4.0%2F%22%3E%3Cimg%20alt%3D%22Creative%20Commons%20License%22%20style%3D%22border-width%3A0%22%20src%3D%22https%3A%2F%2Fi.creativecommons.org%2Fl%2Fby%2F4.0%2F80x15.png%22%20%2F%3E%3C%2Fa%3E%3Cbr%20%2F%3EThis%20work%20is%20licensed%20under%20a%20%3Ca%20rel%3D%22license%22%20href%3D%22http%3A%2F%2Fcreativecommons.org%2Flicenses%2Fby%2F4.0%2F%22%3ECreative%20Commons%20Attribution%204.0%20International%20License%3C%2Fa%3E.%20The%20**MOSEK**%20logo%20and%20name%20are%20trademarks%20of%20%3Ca%20href%3D%22http%3A%2F%2Fmosek.com%22%3EMosek%20ApS%3C%2Fa%3E.%20The%20code%20is%20provided%20as-is.%20Compatibility%20with%20future%20release%20of%20**MOSEK**%20or%20the%20%60Fusion%20API%60%20are%20not%20guaranteed.%20For%20more%20information%20contact%20our%20%5Bsupport%5D(mailto%3Asupport%40mosek.com).%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20return%20(mo%2C)%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
45dd2f056fb35d0fc913c051ed3c335523218e5362a1227ac42734e22bcdcf95