Getting the error "Dimensions of arrays being concatenated are not consistent" but I can't tell why. (See my code in the body of this post)
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I've been working on a coding assignment and keep receiving the error "Dimensions of arrays being concatenated are not consistent." I've narrowed down the location of the error to the following lines of code:
y = [1;1;1]; % this is our initial guess.
% the vector function g:
g = @(y) [2*(y(1)^2) - 4*y(1) + (y(2)^2) + 3*(y(3)^2) + 6*y(3) + 2; (y(1))^2 + (y(2))^2 -2*y(2)+2 (y(3)^2) - 5; 3*(y(1)^2)-12*y(1) + (y(2))^2 + 3*(y(3)^2) + 8];
%calling the vector function g with y = [1;1;1]
g(y)
The code for the vector function g defined above is written as one line in my program (just saying this in case it showed up as two lines in this post). I've been scratching my head with this for a while, I don't see how I can fix the error.
0 comentarios
Respuestas (2)
Walter Roberson
el 10 de Mzo. de 2024
(y(1))^2 + (y(2))^2 -2*y(2)+2 (y(3)^2) - 5
Inside [] that is interpreted as
(y(1))^2 + (y(2))^2 -2*y(2)+2, (y(3)^2) - 5
You are missing an operation between the 2 and the (y(3)^2)
0 comentarios
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!