⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 convex_interpolation.m

📁 斯坦福大学Grant和Boyd教授等开发的凸优化matlab工具箱
💻 M
字号:
% Figure 6.24: Fitting a convex function to given data% Section 6.5.5% Boyd & Vandenberghe "Convex Optimization"% Original by Lieven Vandenberghe% Adapted for CVX by Argyris Zymnis - 11/27/2005%% Here we find the convex function f that best fits% some given data in the least squares sense.% To do this we solve%     minimize    ||yns - yhat||_2%     subject to  yhat(j) >= yhat(i) + g(i)*(u(j) - u(i)), for all i,jclear% Noise level in percent and random seed.rand('state',29);noiseint=.05;% Generate the data setu = [0:0.04:2]';m=length(u);y = 5*(u-1).^4 + .6*(u-1).^2 + 0.5*u;v1=u>=.2;v2=u<=.6;v3=v1.*v2;dipvec=((v3.*u-.4*ones(1,size(v3,2))).^(2)).*v3;y=y+40*(dipvec-((.2))^2*v3);% add perturbation and plots the input datarandf=noiseint*(rand(m,1)-.5);yns=y+norm(y)*(randf);figureplot(u,yns,'o');% min. ||yns-yhat||_2% s.t. yhat(j) >= yhat(i) + g(i)*(u(j) - u(i)), for all i,jcvx_begin    variables yhat(m) g(m)    minimize(norm(yns-yhat))    subject to        yhat*ones(1,m) >= ones(m,1)*yhat' + (ones(m,1)*g').*(u*ones(1,m)-ones(m,1)*u');cvx_endnopts =1000;t = linspace(0,2,nopts);f = max(yhat(:,ones(1,nopts)) + ...      g(:,ones(1,nopts)).*(t(ones(m,1),:)-u(:,ones(1,nopts))));plot(u,yns,'o',t,f,'-');axis off%print -deps interpol_convex_function2.eps

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -