通过a(i,j)= - 1 + 2max(i,j)和b(j)= sum(j到n)a(i,j)来定义n×n矩阵A.然后在这个系统上测试Naive-Gauss(Matlab)

时间:2014-04-28 02:46:25

标签: arrays matlab matrix

使用Naive Gauss测试系统很容易,但我无法定义A和b。我现在的代码如下:

A=zeros(n);


for i=1:n

    for j=1:n
        smax=max(i,j);
        A(i,j)=-1+2*smax;
    end
end

for j=1:n

    sum=0;
    sum=sum+A(i,j);
    b(j)=sum;
end

1 个答案:

答案 0 :(得分:0)

b的定义不明确。总和中i的价值是多少?

假设总和超过了所有i

n = 5; %// matrix size. Set as needed
[ii jj] = ndgrid(1:n);
A = -1+2*max(ii,jj);
b = sum(fliplr(cumsum(fliplr(A),2)));