Re: [問題] 不用迴圈要怎寫出這程式?已回收

看板MATLAB作者 (雁)時間16年前 (2009/10/14 09:32), 編輯推噓0(002)
留言2則, 2人參與, 最新討論串2/2 (看更多)
我試了個方式,將程式分成主程式與副程式 主程式: clear all, clc Loop(1,10); 副程式: % N : 指第幾個回合 % Rounds : 指總共要做幾個回合 function Loop(N, Rounds) count = N; if count <= Rounds R = fix(rand()*10+1); C = fix(rand()*10+1); A = round(rand(R,C)); % 產生一A矩陣, R by C B = round(rand(C,R)); % 產生一B矩陣, C by R if trace(A*B) == trace(B*A) fprintf('tr(AB) == tr(BA)'); else fprintf('tr(AB) ~= tr(BA)'); end Loop(N+1, Rounds); end -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.120.15.195

10/14 13:08, , 1F
沒有寫的很嚴謹,把大概的想法寫出來而已
10/14 13:08, 1F

10/15 00:21, , 2F
感謝大大!!
10/15 00:21, 2F
文章代碼(AID): #1ArIecpG (MATLAB)
文章代碼(AID): #1ArIecpG (MATLAB)