0

I am doing a small research that requires to find the argmin of some function. This is the function I wrote. I want to find a vector x that gives the minimum output of this function. I tried fminsearch(@crc,x), but I got the following error.

Error in fminsearch (line 200)
fv(:,1) = funfcn(x,varargin{:});

Any help or hint would be appreciated.

function crc = SQ(x)
pdfx = gampdf([0:89],x(1),1/x(2));
pdfy =  gampdf([0:89],x(3),1/x(4));
pdfz = conv(pdfx,pdfy);
cdfz= cumsum(pdfz);
h=pdfz./(1-cdfz);
% I = piecewise(0<t<=9, 0.1, 9<t<=14, 0.3, 14<t<=19, 0.9, ...
% 19<t<=24, 1.5, 19<t<=29, 3,  29<t<=34, 5.7, 34<t<=39, 10.5, 39<t<=44, 19,...
% 44<t<=49, 33.1, 49<t<=54, 59.5, 54<t<=59, 68.4, 59<t<=64, 90.2, 64<t<=69,...
% 121.4, 69<t<=74, 153, 74<t<=79, 197.5, 79<t<=84, 237.9, 84<t<=89, 258.8);
I=zeros(1,161);
for t=0:1:89
if 0 < t && t <= 9
        I(t)=.1;
elseif 9<t&& t <=14
        I(t) = 0.3;
elseif 14<t && t<=19 
        I(t) = 0.9;
elseif 19<t&& t <=24
        I(t) = 1.5;
elseif 24<t&& t <=29
        I(t) = 3;
elseif 29<t&& t <=34
        I(t) = 5.7;
elseif 34<t&& t <=39
        I(t) = 10.5;
elseif 39<t&& t <=44
        I(t) = 19;
elseif 44<t&& t <=49
        I(t) = 33.1;
elseif 49<t&& t <=54
        I(t) = 59.5;
elseif 54<t&& t <=59
        I(t) = 68.4;
elseif 59<t&& t <=64
        I(t) = 90.2;
elseif 64<t&& t <=69
        I(t) = 121.4; 
elseif 69<t&& t <=74
        I(t) = 153;
elseif 74<t&& t <=79
        I(t) = 197.5; 
elseif 79<t&& t <=84
        I(t) = 237.9;
elseif 84<t&& t <=89
        I(t) = 258.8;        
     
end
end
I=I/100000;
sqer = sum((h([20:89])-I([20:89])).^2);
end

1 Answer 1

1

The error massage you posted looks incompleted. It will be clearer if you show us the full error message.
Your function is called SQ; crc is the name of its output variable.
Note also that matlab identifies functions by their file names. I assume your function file is named SQ.m.
Try

fminsearch(@SQ,x)
1
  • I tried your suggestion. Thant's supper helpful! Thank you!
    – Chris
    Nov 5, 2021 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.