Borrar filtros
Borrar filtros

Unable to perform assignment because the size of the left side is 4-by-1 and the size of the right side is 4-by-4 Error.

1 visualización (últimos 30 días)
I know a lot of these types of questions have been asked.
I tried to do the whole preallocation thing, but I'm definately doing it wrong. Can anyone help me understand exaclty what preallocation is and how to fix it in this situation?
  1 comentario
Rik
Rik el 1 de Mzo. de 2020
X-X0 is a 4x1 subtracted from a 4x4, so X0 is expanded to 4x4, which results in a 4x4 output of that line of code. You're trying to store that in a column of a matrix.
I have no clue what your intended outcome is (especially with the lack of comments), so I can't suggest an edit.

Iniciar sesión para comentar.

Respuestas (1)

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato el 1 de Mzo. de 2020
The dimensions of your X point and your step are wrong (1x4 and 4x1), you can just transpose one of them to fix your problem
X = X-(j\f)' % Don't use inv to solve linear systems in matlab
Also, your residue should not be individualized but rather depend of the whole vector, so:
err = zeros(1,n);
...
err(i) = norm(X-Xo)
...
if err(i)<tolX
A preallocation is basically saying how much memory a specific variable will use. In some languages this is a must, in matlab most times an option, although you can drastically increase the efficiency of your code with it in cases where the variables are too big and you have many loops, because otherwise at every iteration matlab will have to generate a new array by itself at every iteration.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by