Error in cvx for large-scale model

I have a problem using cvx, I want to minimize x’(Mx+q). I created a small-scale model to verify whether the code would run. However, if I use values of a large-scale model the code will not run and cvx gives the following error: Error using * (line 41)
Inner matrix dimensions must agree.

This is the code I used for both small- and large-scale models. In which M1, q1 and n1 are used for the large- scale and M2, q2 and n2 for the small scale.

M1= [45.3621070380030,45.2334027894835,45.1593253275525,45.2806080504964,45,45.0702282159491,45,45.0778263400460,45.0814989875065,45,45,45.0285591889190,45.0285591889190,45.2313408993695,45,45,45.0681663258350,45,45,45,45,45,45.0285591889190,45.0285591889190,45.0285591889190,45.0285591889190,45.0285591889190,45.0681663258350,45,45,-1,0,0;45.2334027894835,45.5094127702913,45.0987874048681,45.2124417246614,45,45.3462381967569,45,45.0778263400460,45.0209610648221,45,45,45.0285591889190,45.0285591889190,45.1631745735344,45,45,45,45,45,45,45,45,45.0285591889190,45.0285591889190,45.0285591889190,45.0285591889190,45.0285591889190,45,45,45,-1,0,0;44.1593253275525,44.0987874048681,44.2613938956514,44.0778263400460,44,44.0702282159491,44,44.1798949081449,44.1724601469638,44.0909611594573,44,44.0396665975606,44.1030339380333,44.0285591889190,44.0111074086416,44.0744747491143,44,44,44,44,44,44,44.0396665975606,44.0396665975606,44.1030339380333,44.1030339380333,44.1306277570179,44,44,44,-1,0,0;50.2806080504964,50.2124417246614,50.0778263400460,50.5484694682959,50,50.0492671511270,50.0703305536019,50.3456877578455,50,50.2678614177995,50,50.0285591889190,50.0285591889190,50.2313408993695,50,50,50.0681663258350,50,50,50,50,50,50.0285591889190,50.0285591889190,50.0285591889190,50.0285591889190,50.0285591889190,50.0681663258350,50,50,-1,0,0;50,50,50,50,50.5692290807510,50,50.3708607659445,50,50.2507935282914,50.2507935282914,50.3708607659445,50.1200672376531,50,50,50.1200672376531,50,50,50,50,50,50.4333535509004,50.3708607659445,50.1825600226090,50.1200672376531,50.0624927849560,50,50,50,50,50,-1,0,0;52.0702282159491,52.3462381967569,52.0702282159491,52.0492671511270,52,52.5527179092656,52,52.0492671511270,52.0209610648221,52,52,52,52,52,52.1665675193337,52.1665675193337,52.1665675193337,52,52,52,52,52,52,52,52,52,52,52.1665675193337,52,52,-1,0,0;56,56,56,56.0703305536019,56.3708607659445,56,56.6578220373816,56.0703305536019,56.2507935282914,56.3211240818933,56.3708607659445,56.1200672376531,56,56,56.1200672376531,56,56,56,56,56,56.3708607659445,56.5019848570161,56.1200672376531,56.2511913287247,56,56.1311240910716,56,56,56,56,-1,0,0;49.0778263400460,49.0778263400460,49.1798949081449,49.3456877578455,49,49.0492671511270,49.0703305536019,49.4477563259443,49.0909611594573,49.3588225772567,49,49.0396665975606,49.1030339380333,49.0285591889190,49.0111074086416,49.0744747491143,49,49,49,49,49,49,49.0396665975606,49.0396665975606,49.1030339380333,49.1030339380333,49.1306277570179,49,49,49,-1,0,0;57.0814989875065,57.0209610648221,57.1724601469638,57,57.2507935282914,57.0209610648221,57.2507935282914,57.0909611594573,57.5368126123435,57.4553136248370,57.2507935282914,57,57.0633673404727,57,57,57.0633673404727,57,57,57,57,57.2507935282914,57.2507935282914,57,57,57.0633673404727,57.0633673404727,57.0909611594573,57,57,57,-1,0,0;62,62,62.0909611594573,62.2678614177995,62.2507935282914,62,62.3211240818933,62.3588225772567,62.4553136248370,62.7231750426365,62.2507935282914,62,62.0633673404727,62,62,62.0633673404727,62,62,62,62,62.2507935282914,62.2507935282914,62,62,62.0633673404727,62.0633673404727,62.0909611594573,62,62,62,-1,0,0;39,39,39,39,39.3708607659445,39,39.3708607659445,39,39.2507935282914,39.2507935282914,39.4846128459245,39.1844060995973,39.0643388619442,39.0643388619442,39.1443018284924,39,39.0242345908393,39,39,39,39.4603782550852,39.4603782550852,39.1601715087580,39.1601715087580,39.0401042711049,39.0401042711049,39.0401042711049,39,39,39,0,-1,0;38.0285591889190,38.0285591889190,38.0396665975606,38.0285591889190,38.1200672376531,38,38.1200672376531,38.0396665975606,38,38,38.1844060995973,38.3377348931115,38.1040054595048,38.0928980508632,38.2690714330876,38.0111074086416,38.0242345908393,38,38,38,38.1601715087580,38.1601715087580,38.3135003022722,38.3135003022722,38.0797708686655,38.0797708686655,38.0797708686655,38,38,38,0,-1,0;38.0285591889190,38.0285591889190,38.1030339380333,38.0285591889190,38,38,38,38.1030339380333,38.0633673404727,38.0633673404727,38.0643388619442,38.1040054595048,38.3867672712368,38.3122925221226,38.0353419994809,38.2938692203736,38.2436290620987,38,38,38,38.0401042711049,38.0401042711049,38.0797708686655,38.0797708686655,38.3625326803975,38.3625326803975,38.1431382091382,38,38,38,0,-1,0;51.2313408993695,51.1631745735344,51.0285591889190,51.2313408993695,51,51,51,51.0285591889190,51,51,51.0643388619442,51.0928980508632,51.3122925221226,51.5425795044168,51.0242345908393,51.2193944712593,51.3393006597775,51,51,51,51.0401042711049,51.0401042711049,51.0686634600239,51.0686634600239,51.2880579312832,51.2880579312832,51.0686634600239,51.0681663258350,51,51,0,-1,0;51,51,51.0111074086416,51,51.1200672376531,51.1665675193337,51.1200672376531,51.0111074086416,51,51,51.1443018284924,51.2690714330876,51.0353419994809,51.0242345908393,51.5677144241194,51.3097503996734,51.1908021101731,51,51,51,51.1200672376531,51.1200672376531,51.2448368422483,51.2448368422483,51.0111074086416,51.0111074086416,51.0111074086416,51.1665675193337,51,51,0,-1,0;48,48,48.0744747491143,48,48,48.1665675193337,48,48.0744747491143,48.0633673404727,48.0633673404727,48,48.0111074086416,48.2938692203736,48.2193944712593,48.3097503996734,48.5925122114055,48.3859619905931,48,48,48,48,48,48.0111074086416,48.0111074086416,48.2938692203736,48.2938692203736,48.0744747491143,48.1665675193337,48,48,0,0,0;50.0681663258350,50,50,50.0681663258350,50,50.1665675193337,50,50,50,50,50.0242345908393,50.0242345908393,50.2436290620987,50.3393006597775,50.1908021101731,50.3859619905931,50.5058681791112,50,50,50,50,50,50,50,50.2193944712593,50.2193944712593,50,50.2347338451688,50,50,0,-1,0;54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54,54.5349360733912,54.2451103470875,54.1829174477849,54,54,54,54,54,54,54,54,54.4727431740886,54.1829174477849,0,-1,0;50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50,50.2451103470875,50.4902745396201,50.4280816403175,50,50,50,50,50,50,50,50,50.1829174477849,50.4280816403175,0,-1,0;56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56,56.1829174477849,56.4280816403175,56.5784906278805,56,56,56,56,56,56,56,56,56.1829174477849,56.4280816403175,0,-1,0;44,44,44,44,44.4333535509004,44,44.3708607659445,44,44.2507935282914,44.2507935282914,44.4603782550852,44.1601715087580,44.0401042711049,44.0401042711049,44.1200672376531,44,44,44,44,44,44.5228710400411,44.4603782550852,44.2226642937139,44.1601715087580,44.1025970560608,44.0401042711049,44.0401042711049,44,44,44,0,0,-1;50,50,50,50,50.3708607659445,50,50.5019848570161,50,50.2507935282914,50.2507935282914,50.4603782550852,50.1601715087580,50.0401042711049,50.0401042711049,50.1200672376531,50,50,50,50,50,50.4603782550852,50.6111384241775,50.1601715087580,50.3109316778503,50.0401042711049,50.1908644401972,50.0597403491256,50.0196360780207,50,50,0,0,-1;43.0285591889190,43.0285591889190,43.0396665975606,43.0285591889190,43.1825600226090,43,43.1200672376531,43.0396665975606,43,43,43.1601715087580,43.3135003022722,43.0797708686655,43.0686634600239,43.2448368422483,43.0111074086416,43,43,43,43,43.2226642937139,43.1601715087580,43.3759930872281,43.3135003022722,43.1422636536214,43.0797708686655,43.0797708686655,43,43,43,0,0,-1;49.0285591889190,49.0285591889190,49.0396665975606,49.0285591889190,49.1200672376531,49,49.2511913287247,49.0396665975606,49,49,49.1601715087580,49.3135003022722,49.0797708686655,49.0686634600239,49.2448368422483,49.0111074086416,49,49,49,49,49.1601715087580,49.3109316778503,49.3135003022722,49.4642604713645,49.0797708686655,49.2305310377578,49.0994069466862,49.0196360780207,49,49,0,0,-1;43.0285591889190,43.0285591889190,43.1030339380333,43.0285591889190,43.0624927849560,43,43,43.1030339380333,43.0633673404727,43.0633673404727,43.0401042711049,43.0797708686655,43.3625326803975,43.2880579312832,43.0111074086416,43.2938692203736,43.2193944712593,43,43,43,43.1025970560608,43.0401042711049,43.1422636536214,43.0797708686655,43.4250254653535,43.3625326803975,43.1431382091382,43,43,43,0,0,-1;49.0285591889190,49.0285591889190,49.1030339380333,49.0285591889190,49,49,49.1311240910716,49.1030339380333,49.0633673404727,49.0633673404727,49.0401042711049,49.0797708686655,49.3625326803975,49.2880579312832,49.0111074086416,49.2938692203736,49.2193944712593,49,49,49,49.0401042711049,49.1908644401972,49.0797708686655,49.2305310377578,49.3625326803975,49.5132928494898,49.1627742871589,49.0196360780207,49,49,0,0,-1;49.0285591889190,49.0285591889190,49.1306277570179,49.0285591889190,49,49,49,49.1306277570179,49.0909611594573,49.0909611594573,49.0401042711049,49.0797708686655,49.1431382091382,49.0686634600239,49.0111074086416,49.0744747491143,49,49,49,49,49.0401042711049,49.0597403491256,49.0797708686655,49.0994069466862,49.1431382091382,49.1627742871589,49.3714127336441,49.2006807055214,49,49,0,0,-1;49.0681663258350,49,49,49.0681663258350,49,49.1665675193337,49,49,49,49,49,49,49,49.0681663258350,49.1665675193337,49.1665675193337,49.2347338451688,49,49,49,49,49.0196360780207,49,49.0196360780207,49,49.0196360780207,49.2006807055214,49.4354145506901,49,49,0,0,-1;49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49.4727431740886,49.1829174477849,49.1829174477849,49,49,49,49,49,49,49,49,49.4971572365886,49.2073315102849,0,0,-1;45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45,45.1829174477849,45.4280816403175,45.4280816403175,45,45,45,45,45,45,45,45,45.2073315102849,45.4524957028175,0,0,-1;1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0];
    
q1= [3.99750000000000;4.00110000000000;4.56080000000000;3.97670000000000;4.57430000000000;4.01910000000000;3.99480000000000;4.54680000000000;4.60410000000000;4.57500000000000;3.98120000000000;3.99630000000000;3.97130000000000;4.55700000000000;4.00800000000000;3.38480000000000;3.41440000000000;4.60060000000000;4.00100000000000;4.00420000000000;4.58090000000000;4.58310000000000;4.56230000000000;4.57720000000000;4.57340000000000;4.57120000000000;4.58820000000000;2.80940000000000;4.01040000000000;3.39660000000000;-300;-600;-200];

n1 = numel(q1);

M2= [40,0,0,20,0,-1,0;0,60,0,0,20,-1,0;0,0,80,0,0,-1,0;8,0,0,80,0,0,-1;0,4,0,0,100,0,-1;1,1,1,0,0,0,0;0,0,0,1,1,0,0];
q2 = [3543.61540823546;950;3000;4391.48721098062;1300;-260;-170];
n2 = numel(q2);

% Construct and solve the model
fprintf(1,'Computing the optimal solution ...');
cvx_begin
    variables x(n1) 
    minimize ( x'*(M1*x + q1) )
    subject to
    M1*x + q1 >= 0;
    x >= 0;
cvx_end
fprintf(1,'Done! \n');

M1 is not psd. It’s not even symmetric. Even its symmetrized version 0.5*(M1+M1') is not psd. Hence you will get a fatal error message from CVX. because the objective function is not convex… As for “Inner matrix dimensions must agree”, i don’t know whether that is a symptom of the preceding, or is due to some other “configuration control” error by you. Did you check the dimensions of everything with whos?

M2 is also not symmetric, but its symmetrized version is psd, so the objective function is convex, and CVX accepts it.

Thank you for the quick reply, I changed the matrix and now it is psd and running.