Can't find the syntax errors
조회 수: 9 (최근 30일)
이전 댓글 표시
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;
end
norm(residuals,Inf));
solution = [double(a),double(w),double(phi),double(c)];
댓글 수: 5
Johan Löfberg
2022년 5월 19일
and there is no reason to assign initials, as sedumi does not support warmstarts (and even if it did, warmstarting primal-dual solvers with primals only will never help more than absolutely marginally)
Walter Roberson
2022년 5월 19일
It looks as if optimize() was available at least as early as 2010, but that solvesdp was being worked on up to at least 2014.
채택된 답변
Alan Weiss
2013년 5월 2일
편집: Alan Weiss
2013년 5월 2일
Thank you for the clarification. Take a look at these lines, towards the bottom of your code:
solvesdp(constraints,...
for k=1:length(xvals)
Obviously, there should be something in between these lines, to close the parentheses in the solvesdp function. After that, you can write a for loop and it should work correctly.
What I mean is, you need to write your for loop separately, outside the solvedsp function call. You might need to rework the function definition so that it expects the correct thing. Make a variable that is the result of the for loop or something, and pass that variable to the function.
Alan Weiss
MATLAB mathematical toolbox documentation
댓글 수: 3
Rahul Meshram
2022년 5월 17일
clear all; FileName1 = uigetfile("*", "); im101 = imread(FileName1); im102 imresize(im101,[312 312]); K1=im102(:,:,.2); im103 = rgb2gray(im102); im103 = imbinarize(im103); imshow(im103);
FileName2 = uigetfile("** ,"); im201 = imread(FileName2); im202= imresize(im201,[312 312]); K2 =im202(:,:,2); im203 = rgb2gray(im202); im203= imbinarize(im203); imshow(im203);
P1 = detectSURFFeatures(im103); strongest = P1.selectStrongest(200); plot(strongest);
P2 = detectSURFFeatures(im203); [f1,valid_points1] = extractFeatures(im103,P1); [f2,valid_points2] = extractFeatures (im203,P2); indexPairs = matchFeatures(f1,f2);
disp(indexPairs); disp(length(indexPairs));
matchedPoints1 = valid_points 1 (indexPairs(:,1));
matchedPoints2 = valid_points2(indexPairs(:,2));
figure; ax = axes; showMatchedFeatures(im103,im203,matchedPoints1,matchedPoints2, montage','Parent',ax)
title('Counterfeit Currency Detection');
if length(indexPairs) >=80 msgbox('Currency Is Real");
else msgbox('Currency Is Counterfeit'); end
Here is one error occurred, this is syntax error. How can I solve for fake currency detection
Walter Roberson
2022년 5월 18일
im102 imresize(im101,[312 312]);
missing assignment operator
추가 답변 (1개)
Alan Weiss
2013년 5월 2일
Please show us the errors you get.
Alan Weiss
MATLAB mathematical toolbox documentation
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!