Aeq must have two columns error???

this is my Aeq and beq:
swtOther_Aeq = [ 1 0 1 0 0 0 1 0 0 0 ]; swtOther_beq = [ 0.22 ];
yet matlab is telling me Aeq needs two columns.
I'm confused as to why. Can someone help me out? Thanks please.

3 Comments

We need a bit more information. What function are you using, what equality constraints do you want to impose on your parameters, what are your parameters, what is your model, and what are your data?
You do not have to post all your code and data, but enough for us to have a context for your Question.
All of us are good, some of us are brilliant, but none of us are mind-readers.
well swtOther_Aeq right now means that stocks 1,3,7 should add up their weights to 22% (0.22) as depicted in the portfolio. This is in a control panel that can be switched up by someone who wants to run different stock weights ie the person can make 2,3,4 add to .15.
I am trying to minimize the variance of the portfolio, which has 10 (swtN) stocks.
this is what my fmincon looks like. W is a vector:
[W] = fmincon('objfun',x0,swtOther_A,swtOther_b,swtOther_Aeq,swtOther_beq,swtMinWt1,swtMaxWt1,[],options);
when i tried to run the program, it didnt give me error for swtotherA and b, so I dont know what is going wrong.
Thanks.
If the variance is a quadratic function of the weights, you should use quadprog instead of fmincon.

Sign in to comment.

Answers (1)

Matt J
Matt J on 28 May 2014
Edited: Matt J on 28 May 2014
You are passing an x0 with only 2 elements. The length of x0(:) should equal 10.

13 Comments

my x0 is [-1,1]. how do i make it 10 elements?
Matt J
Matt J on 28 May 2014
Edited: Matt J on 28 May 2014
If you have 10 stocks, what motivated you to give x0 only 2 elements?
Sameer
Sameer on 28 May 2014
Edited: Matt J on 28 May 2014
if swtERMin > -inf;
x0 = zeros(1,swtN)+0.10;
elseif swtERMin == -inf;
x0 = zeros(1,swtN)+0.10;
end;
does this work?
Why not just
x0(1:swtN)=0.10;
does x0 have to be defined as a matrix first?
What happened when you tried it?
it works but i dont get it.
If you found that it works, I think you've answered your own question. If the variable x0 does not exist yet, it can be defined with an assignement statement
x0(1:N)=targetvalue;
This is one way (a compact one) of creating a length-N vector whose every entry is targetvalue.
when i run the program for fmincon, it said that my objective function is not working.
function [f] = objfun(W,VCVMatx)
%function for varience of the portfolio with swtN stocks
f = W*VCVMatx*W';
when i run that in the main program it says it does not have enough input arguments. would you happen to know why?
Matt J
Matt J on 28 May 2014
Edited: Matt J on 28 May 2014
Make sure you saw my Comment here.
If you insist on using fmincon, you must tell it how to pass VCVMatx to objfun. One option would be to call fmincon as follows
VCVMatx=...whatever...;
fun=@(W) objfun(W,VCVMatx);
fmincon(fun,x0,...otherarguments...);
in fmincon why use fun instead of objfun in the first space?
its now telling me "inner matrix dimensions must agree". i tried using dot multiplication but it does not work.
"inner matrix dimensions must agree"
These are the kinds of errors that you troubleshoot using the dbstop command.

Sign in to comment.

Asked:

on 28 May 2014

Commented:

on 28 May 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!