MATLAB: Error using / Matrix dimensions must agree.

dimensionerror using *matrix

Hello everyone, can you please help me with this problem? I currently in my project's for Iterative Method. But I can't run the coding because of this problem.
Delamda = DelP/J;
Attached below is my full coding, can you guys help me?
clear
clc
a = [671 574 374 374 461 630 548 227 173 175 186 230 225 309 323];
b = [10.1 10.2 8.8 8.8 10.4 10.1 9.8 11.2 11.2 10.7 10.2 9.9 13.1 12.1 12.4];
c = [0.000299 0.000183 0.001126 0.001126 0.000205 0.000301 0.000364 0.000338 0.000807 0.001203 0.003586 0.005513 0.000371 0.001929 0.004446];
PD = 2630;
DelP = 10;
% define fuel cost quaratic equation
cost = [671 10.1000 0.000299
574 10.2000 0.000183
374 8.8000 0.001126
374 8.8400 0.001126
461 10.4000 0.000205
630 10.1000 0.000301
548 9.8000 0.000364
227 11.2000 0.000338
173 11.2000 0.000807
175 10.7000 0.001203
186 10.2000 0.003586
230 9.9000 0.005513
225 13.1000 0.000371
309 12.1000 0.001929
323 12.4000 0.004446];
% define Pi_min and Pi_max
mwlimits = [150 455
150 455
20 130
20 130
150 470
135 460
135 465
60 300
25 162
25 160
20 80
20 80
25 85
15 55
15 55];
Pdt = 2630;
lamda = input('Enter estimated value of Lamda = ');
fprintf(' ')
disp ['Lamda P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P13 P14 P15 DP'...' grad Delamda'];
iter = 1;
while abs(DelP) >= 0.001
iter = iter + 1;
P = (lamda - b)./(2*c);
DelP = PD - sum(P);
J = sum(ones(length(a),1)./(2*c));
Delamda = DelP/J;
disp [lamda,P(1),P(2),P(3),P(4),P(5),P(6),P(7),P(8),P(9),P(10),P(11),P(12),P(13),P(14),P(15)DelP,J,Delamda];
lamda = lamda + Delamda;
end
totalcost = sum(a + b.*P + c.*P.^2);

Best Answer

If you make it an element-wise division, your code will run without errors. Since you still haven't really explained anything you're doing, I don't know if the result makes any sense.
Delamda = DelP./J;
% ^ add that
Test on the full code:
lamda = 8.35;
a = [671 574 374 374 461 630 548 227 173 175 186 230 225 309 323];
b = [10.1 10.2 8.8 8.8 10.4 10.1 9.8 11.2 11.2 10.7 10.2 9.9 13.1 12.1 12.4];
c = [0.000299 0.000183 0.001126 0.001126 0.000205 0.000301 0.000364 0.000338 0.000807 0.001203 0.003586 0.005513 0.000371 0.001929 0.004446];
PD = 2630;
DelP = 10;
% define fuel cost quaratic equation
cost = [671 10.1000 0.000299 ; 574 10.2000 0.000183 ; 374 8.8000 0.001126 ; ...
374 8.8400 0.001126 ; 461 10.4000 0.000205 ; 630 10.1000 0.000301 ; ...
548 9.8000 0.000364 ; 227 11.2000 0.000338 ; 173 11.2000 0.000807 ; ...
175 10.7000 0.001203 ; 186 10.2000 0.003586 ; 230 9.9000 0.005513 ; ...
225 13.1000 0.000371 ; 309 12.1000 0.001929 ; 323 12.4000 0.004446];
% define Pi_min and Pi_max
mwlimits = [150 455;150 455;20 130;20 130;150 470;...
135 460;135 465;60 300;25 162;25 160;20 80;...
20 80;25 85;15 55;15 55];
Pdt = 2630;
iter = 1;
while abs(DelP) >= 0.001
iter = iter + 1;
P = (lamda - b)./(2*c);
DelP = PD - sum(P);
J = sum(ones(length(a),1)./(2*c));
Delamda = DelP./J;
lamda = lamda + Delamda;
end
totalcost = sum(a + b.*P + c.*P.^2);
disp(totalcost)
1.0925e+05