trying to iterate through a vector changing the value of 1/5 in each iteration ?

2 ビュー (過去 30 日間)
Luis Garcia
Luis Garcia 2018 年 2 月 27 日
コメント済み: Jos (10584) 2018 年 2 月 27 日
Im trying to do calculations with x with different b, so for example the first calculation is with b = 1/5 0 0 0 0 0 0 0 ....
then the next calculation with x will be with 1/5 now being in second index like b = 0 1/5 0 0 0 0 0 ......
till the last calculation b = 0 0 0 0 0 0.......1/5.
b = zeros(size(A,1),1);
>> b(1) = 1/5;
>> for i=1:size(A,1);
x = A\b;
b(i+1) = b(i);
b(i-1) = 0;
end

採用された回答

Stephen23
Stephen23 2018 年 2 月 27 日
編集済み: Stephen23 2018 年 2 月 27 日
N = size(A,1);
for k = 1:N
b = zeros(1,N);
b(k) = 1/5;
x = A\b;
end
  1 件のコメント
Jos (10584)
Jos (10584) 2018 年 2 月 27 日
N = size(A,1);
b = zeros(1,N);
for k = 1:N
b(k) = 1/5;
x = A\b;
b(k) = 0 ;
end

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by