How can I create one vector x to have this function correct? x has to be the column vector k- 'th of A, from its diagonal to the end

5 ビュー (過去 30 日間)
function [Q, R] = miqr(A)
[nr,nc]=size(A);
Q=eye(nr);
k=A(:,1:nc-1);
x=k(2:nr,nc); --> the error is here, it says "index in position 2 exceeds array bounds(musn not exceed 4)
H=Householder(VecHh(x));
P=blkdiag(1,H);
A=P*A;
Q=P*Q;
R=A;
Q=Q';
end
okay, thank you so much, i dont know what value of x i am expecting, the only request for my exercise is that x has to be the column vector k- 'th of A, from its diagonal to the end
the excercise is create one random array and then apply the function something like this :
>> A=rand(5)
A =
0.8147 0.0975 0.1576 0.1419 0.6557
0.9058 0.2785 0.9706 0.4218 0.0357
0.1270 0.5469 0.9572 0.9157 0.8491
0.9134 0.9575 0.4854 0.7922 0.9340
0.6324 0.9649 0.8003 0.9595 0.6787
>> [Q, R] = miqr(A)
Index in position 2 exceeds array bounds (must not exceed 4).
Error in miqr (line 5)
x=k(2:nr,nc);
* but here is y error *
function A = Householder(v)
%% Householder matrix of base v
v = reshape(v,length(v),1); % v is now a column vector
A = eye(length(v)) - 2* v*v' /norm(v)^2;
end
  3 件のコメント
Ridwan Alam
Ridwan Alam 2019 年 12 月 11 日
what is k supposed to be? is it supposed to be an input to the miqr() like [Q,R]=miqr(A,k)?

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

回答 (1 件)

Ridwan Alam
Ridwan Alam 2019 年 12 月 11 日
k has size nr x (nc-1). you are trying to assign x = k(2:nr,nc) which means the nc-th column of k. but k doesn't have nc-th column, it has nc-1 columns.
Now for me to debug more, you need to let me know what H=Householder(VecHh(x)) is doing and what size and value of x are you expecting.

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by