CVX example for verification of a property of Chebyshev polynomial
Suppose \(p(x)\) is a polynomial of degree \(\leq n\) which is bounded in \([-1,+1]\) for \(x \in[-1,+1]\). What is the largest \(p^{\prime}(0)\) can be?
clear all; clc;
x = rand(5000,1)*2 - 1;
deg = 4;
cvx_begin
variable a(deg + 1)
maximize a(2)
subject to
sum = a(1);
for i = 1:deg
sum = sum + a(i+1)*x.^(i);
end
-1 <= sum <= 1
cvx_end
a
Another method based on Matlab's optimization toolbox.
x0 = [0.5;0.5;0.5;0.5];
deg = 3;
x = rand(5000,1)*2 - 1;
A1 = [ones(5000,1) x x.^2 x.^3];
A2 = -A1;
A = [A1;A2];
b = [ones(5000,1);ones(5000,1)];
% Set nondefault solver options
options = optimoptions("fmincon","Display","iter","PlotFcn",...
"optimplotfvalconstr");
% Solve
[solution,objectiveValue] = fmincon(@objectiveFcn,x0,A,b,[],[],[],[],[],...
options);
% Clear variables
clearvars options
function f = objectiveFcn(optimInput)
% Example:
% Minimize Rosenbrock's function
% f = 100*(y - x^2)^2 + (1 - x)^2
% Edit the lines below with your calculation
% x = optimInput(1);
% f = optimInput(2)^2/(optimInput(1)^2-1);
f = -optimInput(2);
end