Error using / Matrix dimensions must agree.
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Muhammad Ezree Amree bin Amran
el 5 de En. de 2021
Comentada: Rik
el 25 de Feb. de 2021
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);
4 comentarios
Hadi Jalali
el 25 de Feb. de 2021
Hi friends. I want to need a code to solve ELD by third degree cost fuel. But I have no idea. Please help me Best wishes H. Jalali
Rik
el 25 de Feb. de 2021
@Hadi Jalali That sounds like a poorly phrased question unrelated to this one. Have a read here and here. It will greatly improve your chances of getting an answer.
Respuesta aceptada
Rik
el 5 de En. de 2021
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)
2 comentarios
Rik
el 5 de En. de 2021
You're welcome. If I solved your issue, please consider marking it as accepted answer.
Also some general advice: use functions and write comments. Every line (or at least few lines) should have a comment explaining the idea behind it (i.e. explain why), and your function should explain the syntax (input options), and the expected output.
%not this:
%multiply v and t
s=v*t;
%but this:
%calculate traversed path length
s=v*t;
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!