MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   MATLAB矩阵格式不正确 (https://www.labfans.com/bbs/showthread.php?t=24029)

poster 2019-12-10 20:48

MATLAB矩阵格式不正确
 
我下面有一些代码,我似乎无法正确设置矩阵的格式。我一直在尝试使矩阵与\ t和fprintf看起来更加专业(并列),但似乎无法做到。我在为矩阵的每一列输入标题时也遇到了麻烦。任何帮助将非常感激!

clear all clc format('bank') % input file values % A = [4 6 5 1 0 0 0 0 0; 7 8 4 0 1 0 0 0 0; 6 5 9 0 0 1 0 0 0; 1 0 0 0 0 0 -1 0 0; 0 1 0 0 0 0 0 -1 0; 0 0 1 0 0 0 0 0 -1]; b = [480; 600; 480; 24; 20; 25]; c = [3000 4000 4000 0 0 0 0 0 0]; % Starting xb % xb = [1 2 3 4 5 6] % Starting xn % xn = [7 8 9] cb = c(xb) cn = c(xn) % Get B from A % B = A(:,xb) % Get N from A % N = A(:,xn) % Calculate z % z = ((cb*(inv(B))*A)-c) % Calculate B^(-1) % Binv = inv(B) % Calculate RHS of row 0 % RHS0 = cb*Binv*b % Calculates A % A = Binv*A %STARTING Tableau% ST = [z RHS0;A b] for j=1:A fprintf(1,'\tz%d',j) end q = 0 while q == 0 m = input('what is the index value of the ENTERING variable? ') n = input('what is the index value of the LEAVING variable? ') xn(xn==m)= n xb(xb==n) = m cb = c(xb) cn = c(xn) B = A(:,xb) N = A(:,xn) Tableuz = (c-(cb*(B^(-1))*A)) RHS0 = (cb*(B^(-1))*b) TableuA = ((B^(-1))*A) Tableub = ((B^(-1))*b) CT = [Tableuz RHS0; TableuA Tableub]; disp(CT) q = input('Is the tableau optimal? Y-1, N-0') end

[B]回答:[/B]

我没有深入研究您正在做的事情,但有几点要注意:*将分号放在您不想打印到屏幕上的行的末尾,这样可以更轻松地查看其他地方发生的情况。 *您的j = 1:循环仅打印j。我认为您想要的更像是这样:

for row = 1:size(A,1) for column = 1:size(A,2) fprintf('%10.2f', A(row,column)); end fprintf('\n'); end [LIST][*]如果您还没有使用过Matlab调试器,请尝试一下。它使许多这些问题更容易发现。要启动它,您要做的就是通过单击行号旁边的破折号(-)并启动脚本来向文件添加一个断点。快速的网络搜索也可以很快地提供解决方案-通常其他人已经遇到了您将遇到的任何问题。[/LIST]祝好运。



[url=https://stackoverflow.com/questions/3983557]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 23:18

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.