Defining matrices to solve Ax=b using a(i,j)=-1+2max(i,j) and b(j)=sum(j to n) a(i,j)

So I have to define these matrices and then using some numerical analysis methods to solve the system Ax=b. What I have so far is,
function x=NaiveGauss(n)
A=zeros(n);
for i=1:n
for j=1:n
smax=max(i,j);
A(i,j)=-1+2*smax
end
end
sum=0;
for j=1:n
sum=sum(A,2)
end
However I can't get the b matrix to be right. Its supposed to be a nx1 matrix that is the sum of each row but the output keeps telling me that the index exceed matrix dimension. Can anyone possibly help me with this loop? Thanks.

 採用された回答

Sara
Sara 2014 年 4 月 28 日
Replace your code with:
summ=0;
for j=1:n
summ=sum(A,2)
end
so there is no confusion between the variable summ and the function sum.

1 件のコメント

Matthew
Matthew 2014 年 4 月 28 日
Thanks, I didn't realize Matlab would confuse the two

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

タグ

質問済み:

2014 年 4 月 28 日

コメント済み:

2014 年 4 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by