Borrar filtros
Borrar filtros

output for linprog to generate table view

1 visualización (últimos 30 días)
ray brunkow
ray brunkow el 19 de Feb. de 2016
Editada: ray brunkow el 20 de Feb. de 2016
hello, I am working on making the output of my code visually nicer. yes this is homework, but I already have the correct answers and working code for the homework problem. I understand the homework, now I am attempting to just clean the output up to make it readable by others outside of the class.
if true
% code
L1 = 250;
L2 = 200;
L3 = 200;
f = [40; 50; 55; 0; 0;];
Aeq = [1 1 1 0 0 ;
0 1 0 -15 5;
0 0 1 5 -13 ];
Beq1 = [10; 3.5; 4.5];
Beq2 = [11; 3.5; 4.5];
Beq3 = [9; 3.5; 4.5];
Aineq = [0 0 0 -10 0;
0 0 0 10 0;
0 0 0 0 -8;
0 0 0 0 8;
0 0 0 -5 5;
0 0 0 5 -5];
Bineq = [L1;L1;L2;L2;L3;L3]/100;
lb = [0; 0; 0; -pi; -pi];
ub = [8.2; 6; 6.1; pi; pi ];
% Hour 1
fprintf('Homework #2 problem #1 EEL-4932 Intro to Smart Grid Spring 2016.\n')
fprintf('Raymond L. Brunkow\n\n')
[x,fval,exitflag,output,lambda] = linprog(f, Aineq, Bineq, Aeq, Beq1, lb, ub);
x(1)=x(1)*100;
x(2)=x(2)*100;
x(3)=x(3)*100;
cost = 40*x(1) + 50*x(2) + 55*x(3);
fprintf('\nThe cost for hour 1 is $%4.2f per MW.\n',cost);
fprintf('The following values for PG1, PG2, PG3, Gamma 2, and Gamma 3 are as follows:\n');
disp(x);
end
That is the working code. For Beq2 & 3 the output sections are the same for hours 2 and 3 so no need to copy/paste them here.
The output I am getting is as follows:
if true
% code
The cost for hour 1 is $44750.00 per MW.
The following values for PG1, PG2, PG3, Gamma 2, and Gamma 3 are as follows:
650.0000
100.0000
250.0000
-0.2500
-0.2500
end
What I would like to do is somehow in a matrix or table like output add the following vector/column:
if true
% code
PG1
PG2
PG3
Gamma 2
Gamma 3
end
Such that they line up with the output from linprog to look something like:
if true
% code
The cost for hour 1 is $44750.00 per MW.
The following values for PG1, PG2, PG3, Gamma 2, and Gamma 3 are as follows:
PG1 650.0000
PG2 100.0000
PG3 250.0000
Gamma 2 -0.2500
Gamma 3 -0.2500
end
Is that even possible? If so how? If not, well that is good too.
Thank you all in advance.

Respuesta aceptada

Wolfgang
Wolfgang el 19 de Feb. de 2016
Editada: Wolfgang el 19 de Feb. de 2016
For example: replace
disp(x)
with
fprintf('PG1 %20.4f \nPG2 %20.4f \nPG3 %20.4f \nGamma 2 %16.4f \nGamma 3 %16.4f',x)
A detailed description of how to format strings is given in http://de.mathworks.com/help/matlab/matlab_prog/formatting-strings.html

Más respuestas (1)

ray brunkow
ray brunkow el 20 de Feb. de 2016
Editada: ray brunkow el 20 de Feb. de 2016
That worked great. Many thanks.
fprintf('PG1 %20.2f MW\nPG2 %20.2f MW\nPG3 %20.2f MW\nGamma 2%17.2f rad\nGamma 3 %16.2f rad\n',x)
the output is now:
PG1 650.00 MW
PG2 100.00 MW
PG3 250.00 MW
Gamma 2 -0.25 rad
Gamma 3 -0.25 rad
Thank you.

Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by