简体   繁体   中英

Using for-loop to generate vectors in Octave/Matlab

I am writing a script for generating the vectors and Hilbert matrix of order n,in which the vector x0 should change its size according to the size of the matrix. But there's an error message saying 'operator *: nonconformant arguments (op1 is 2x2, op2 is 12x1)' May I know why the size of matrix could not be changed successfully, while my vector works well?

for k=2:12

  H = hilb(k);
  x0(1:k)=1;
  b = H * x0'; %generate the n-vector b=Hx0
  x_approx = GE(H,b);
end

The problem is with the vector, and line

x0(1:k)=1;

which does not change the size of the vector when k = 2 . Instead it sets the first k elements of x0 to 1. I would assume that x0 is already set elsewhere as a 12-dimensional vector.

You could try

x0 = ones(1,k);

instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM