I am using MATLAB, SeduMi and YALMIP to implement the algorithm published here. I know I have SeDuMi and YALMIP installed correctly. Before implementing that complicated algorithm, I wanted to use the same approach on an easier problem. With that in mind I tried the code that below, but I get syntax errors. Please show me how to fix the errors. If you can get it working that's even better. The syntax errors are:
- Keyword for is underlined red with the message: "Invalid use of keyword."
- norm(residulas,Inf)); has the right most ')' underlined red with the message:"Parse error at ')': usage might be invalid MATLAB syntax."
- Keyword end is underlined red with the message: "Parse error at END: usage might be invalid MATLAB syntax."
addpath(genpath('C:\Program Files\MATLAB\R2010b\toolbox\yalmip'))path(path,'D:\Documents and Settings\My Documents\MATLAB\SeDuMi_1_1')path(path, 'D:\Documents and Settings\My Documents\MATLAB\SeDuMi_1_1\convr')xvals = 1:0.1:7;yvals = -xvals.^2+8*xvals-15.5;residuals = zeros(length(xvals));% a, w, phi, c are parameters to be optimized
a = sdpvar(1,1);w = sdpvar(1,1);phi = sdpvar(1,1);c = sdpvar(1,1);delta_step = sdpvar(4,1);options = sdpsettings('solver','sedumi','usex0',1,'verbose',1);assign(a,-10.58);assign(w,0.47);assign(phi,1.2);assign(c,-9.87);% determine values of a, w, phi, c that give a minimax
% approximation of (yvals, xvals) using y = a*cos( w*x + phi) + c
% BTW: It seems the solution is y = -10.6072*cos(0.4729*x+1.25)-9.9049
constraints = [ -11<=a<=-9, 0.35<=w<=0.7, 0.8<=phi<=1.25, -11<=c<=-6,... norm(delta_step,2)<=0.04 ];% 2nd argument of solvesdp is a for loop followed by norm(residuals,inf)
solvesdp(constraints,...for k=1:length(xvals) xval=xvals(k); yval=yvals(k); % gradient of (a*cos( w*x + phi) + c) WRT (a,b,phi,c)
gradient = [cos(w*xval)+phi,-a*xval*sin(w*xval)+phi,... -a*sin(w*xval)+phi,1]; step=gradient*(delta_step); residuals(k)=yval-(a*cos(w*xval+phi)-c)+step;endnorm(residuals,Inf));solution = [double(a),double(w),double(phi),double(c)];
Best Answer