【发布时间】:2015-08-18 18:24:43
【问题描述】:
这是我目前计算的平均需要多长时间的代码,MATLAB 在大小为 N=200 的矩阵上实现高斯消元:
Ntr=50; % Number of trials
N=200; % Matrix size
times=zeros(Ntr,1); % Vector of timing data for Ntr trials
for i=1:Ntr
% Form a random matrix A and right-hand side b (normally distributed)
A=randn(N,N);
b=randn(N,1);
% Apply backslash and calculate time taken
tic;
x=A\b;
times(i)=toc;
end
N
mean_time=mean(times)
如何修改此代码,以便它针对各种 N 值(例如 N=200、500、1000、3000 等)进行计算?我尝试了一个 for 循环,但 randn 只能接受标量值...... 我正在寻找的最终结果是绘制 N 值与平均所用时间的对数图。 任何帮助将不胜感激!
【问题讨论】:
标签: matlab for-loop matrix plot gaussian