MATLAB: LINPROG requires the following inputs to be of data type double: ‘f’.

linprogoptimization

I received the following error in calling LINPROG
f=@(weit)LPSOLVE_TRADE(weit,CurrWeights,5,2);
tt=linprog(f,[],[],aeq,beq,lb,ub,weit);
f refers to LPSOLVE_TRADE which has following header
function f=LPSOLVE_TRADE(wei,CurrWeights,numtickers,numaccts)
at the end of function i have f=double(variable name)
Any advice/help guidance would be highly appreciated

Best Answer

linprog only accepts a vector for its first argument, not a function handle.
You are also passing an additional parameter beyond lb. A parameter in that position is used for x0, which is only paid attention to for Active-Set, but Active-Set needs to be specifically requested in an options argument and you have not passed an options argument.
I speculate that what you want is possibly
f = LPSOLVE_TRADE(weit,CurrWeights,5,2);
tt = linprog(f,[],[],aeq,beq,lb,ub);
That is, call LPSOLVE_TRADE with one particular weit, and use that as the vector for linprog.