Why am I getting the error message "??? Assignment has more non-singleton rhs dimensions than non-singleton subscripts"?

1 view (last 30 days)
Hi all,
Please help me to solve this problem.
clear all
clc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % % %%%read data
% filename = 'D_test2.xlsx';
% sheet = 1;
% xlRange = 'A2:E60';
%
% Mm = xlsread(filename, sheet, xlRange);
% %
% % %Get the data
% % %X=(Mm(:,1:13)); %%% money ens data
% HB=(Mm(:,2)); %%% hauteur brute
% P=(Mm(:,3)); %%% puissance
% QTU=(Mm(:,1));%%débit turbiné
% Rg=(Mm(:,4));
% k=0.00981;
% m=(Mm(:,5));
%
% x1=QTU(:);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % %%%read data
% % filename = 'D_final.xlsx';
% % sheet = 1;
% % xlRange = 'A2:AG8761';
% %
% % Mm = xlsread(filename, sheet, xlRange);
% % % pause
% % % Get the data
% % % X=(Mm(:,1:13)); %%% money ens data
% % HB=(Mm(:,17)); %%% hauteur brute
% % P=(Mm(:,1)); %%% puissance
% % QTU=(Mm(:,11));%%débit turbiné
% % % hf=(Mm(:,22));%perte de charge dans la conduite
% % AMONT=(Mm(:,15));%hauteur amont
% % CdF=(Mm(:,16));%hauteur aval
% % % R=(Mm(:,23));%rendement
% % m=(Mm(:,25));%durée
% % % rhf=(Mm(:,26));
% % Rg=(Mm(:,27));
% % k=0.00981;
% % % X=(Mm(:,31));
% % % hmin=36.5;
% % % hmax=41.5;
% % % qmin=130;
% % % qmax=152;
% % x1=QTU(:);
% % hfb=AMONT(:);
% % htr=CdF(:);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%P QTU AMONT CdF HB R Rg
GG=[
296 845.7143 528.2500 488 40.2500 0.7475 0.8864
247 705.7143 528.2700 488 40.2700 0.6237 0.8860
246 702.8571 528.2400 488 40.2400 0.6212 0.8866
256 731.4286 528.2000 488 40.2000 0.6465 0.8875
265 757.1429 528.2600 488 40.2600 0.6692 0.8862
286 817.1429 528.2500 488 40.2500 0.7222 0.8864
273 780 528.2300 487.5000 40.7300 0.6894 0.8760
265 757.1429 528.3000 487.5000 40.8000 0.6692 0.8745
351 1.0029e+03 528.1000 487.6000 40.5000 0.8864 0.8809
349 997.1429 528.0600 487.7000 40.3600 0.8813 0.8840
365 1.0429e+03 528 487.7000 40.3000 0.9217 0.8853
359 1.0257e+03 528.1600 487.7000 40.4600 0.9066 0.8818
347 991.4286 528.3000 487.7000 40.6000 0.8763 0.8788
351 1.0029e+03 528.3000 487.7000 40.6000 0.8864 0.8788
368 1.0514e+03 528.2000 487.7000 40.5000 0.9293 0.8809
358 1.0229e+03 528.1400 487.7000 40.4400 0.9040 0.8822
359 1.0257e+03 528.0800 487.7000 40.3800 0.9066 0.8836
346 988.5714 528.1800 487.7000 40.4800 0.8737 0.8814
377 1.0771e+03 528.1500 488 40.1500 0.9520 0.8886
373 1.0657e+03 528.2100 488 40.2100 0.9419 0.8873
376 1.0743e+03 528.2400 488 40.2400 0.9495 0.8866
367 1.0486e+03 528.2000 488 40.2000 0.9268 0.8875
355 1.0143e+03 528.1800 488 40.1800 0.8965 0.8880
309 882.8571 528.2300 488 40.2300 0.7803 0.8868
276 788.5714 528.2500 488 40.2500 0.6970 0.8864
254 725.7143 528.2600 488 40.2600 0.6414 0.8862
253 722.8571 528.2600 488 40.2600 0.6389 0.8862
250 714.2857 528.2700 488 40.2700 0.6313 0.8860
258 737.1429 528.2400 488 40.2400 0.6515 0.8866
292 834.2857 528.1600 488 40.1600 0.7374 0.8884
280 800 528.1600 488.6000 39.5600 0.7071 0.9019
303 865.7143 528.2000 488.6000 39.6000 0.7652 0.9010
312 891.4286 528.1000 488.6000 39.5000 0.7879 0.9032
343 980.0000 528 488.6000 39.4000 0.8662 0.9055
345 985.7143 528.0600 488.6000 39.4600 0.8712 0.9042
333 951.4286 528.1800 488.6000 39.5800 0.8409 0.9014
329 940.0000 528.2400 488.6000 39.6400 0.8308 0.9000
315 900.0000 528.2800 488.6000 39.6800 0.7955 0.8991
338 965.7143 528.2000 488.6000 39.6000 0.8535 0.9010
328 937.1429 528.1000 488.6000 39.5000 0.8283 0.9032
315 900.0000 528.1000 488.6000 39.5000 0.7955 0.9032
317 905.7143 528.1000 488.6000 39.5000 0.8005 0.9032
358 1.0229e+03 528.0400 487.9000 40.1400 0.9040 0.8888
371 1060 528.1200 487.9000 40.2200 0.9369 0.8871
373 1.0657e+03 528.2200 487.9000 40.3200 0.9419 0.8849
364 1040 528.2500 487.9000 40.3500 0.9192 0.8842
348 994.2857 528.2100 487.9000 40.3100 0.8788 0.8851
296 845.7143 528.2400 487.9000 40.3400 0.7475 0.8844
267 762.8571 528.2200 487.9000 40.3200 0.6742 0.8849
242 691.4286 528.2800 487.9000 40.3800 0.6111 0.8836
243 694.2857 528.2800 487.9000 40.3800 0.6136 0.8836
238 680 528.2600 487.9000 40.3600 0.6010 0.8840
242 691.4286 528.2200 487.9000 40.3200 0.6111 0.8849
251 717.1429 528.2000 487.9000 40.3000 0.6338 0.8853
267 762.8571 528.2900 487.3000 40.9900 0.6742 0.8704
222 634.2857 528.1000 487.3000 40.8000 0.5606 0.8745
267 762.8571 527.9000 487.3000 40.6000 0.6742 0.8788
262 748.5714 527.9000 487.3000 40.6000 0.6616 0.8788
270 771.4286 528.1800 487.3000 40.8800 0.6818 0.8727
273 780 528.3000 487.3000 41.0000 0.6894 0.8702];
P=GG(:,1);
QTU=GG(:,2);
hfb=GG(:,3);
htr=GG(:,4);
HB=GG(:,5);
Rg=GG(:,7);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% options = optimset('PlotFcns',@optimplotfval);
%options = optimset('PlotFcns',@optimplotfval);
opts = optimset('fminsearch');
%opts = optimset('fminsearch',@optimplotfval);
opts.Display = 'iter';
opts.TolX = 1.e-12;
%opts.TolFun = 1.e-12;
opts.MaxFunEvals = 100;
sse =@(x)QTU-sum(x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8));
x0=[ones(60,1),ones(60,1),ones(60,1),ones(60,1),ones(60,1),ones(60,1),ones(60,1),ones(60,1)];
n=length(x0);
LB=[0*ones(n,1) zeros(n,1) zeros(n,1) zeros(n,1) zeros(n,1) zeros(n,1) zeros(n,1) zeros(n,1)];
UB=[152*ones(n,1) 152*ones(n,1) 152*ones(n,1) 152*ones(n,1) 152*ones(n,1) 152*ones(n,1) 152*ones(n,1) 152*ones(n,1)];
%sse = fminsearch(sse,x0,options)
%xsol = fminsearchbnd(sse,x0,LB,UB,opts)
[xsol,fval,exitflag,output] = fminsearchbnd(sse,x0,LB,UB)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Answers (1)

Walter Roberson
Walter Roberson on 10 Oct 2019
Function to minimize, specified as a function handle or function name. fun is a function that accepts a vector or array x and returns a real scalar f (the objective function evaluated at x).
QTU=GG(:,2);
That is 60 x 1
sse =@(x)QTU-sum(x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8));
That is 60 x 1 minus the sum() of what is a scalar because x(1) each each name scalars and + operation between scalars gives a scalar. The sum() there is confusing. 60 x 1 minus a scalar is 60 x 1. However we see from the above that you must return a scalar.
fminsearchbnd() is not suitable for minimizing a multi-objective system: gamultiobj() is the best routine for that.
  14 Comments
Daniel Mbadjoun
Daniel Mbadjoun on 24 Oct 2019
I want to have equal x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)=QTU as a constraint. I want a solution for each equation. I expect in my formulation to obtain 60 equations which have 8 variables per equation plus non-linear equality and inequality constraints (x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)=QTU and x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8)<=QTU) .

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!