フィルターのクリア

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 ビュー (過去 30 日間)
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.

回答 (2 件)

Rex
Rex 2024 年 3 月 10 日
Nevermind guys, it seems it had to do with my order of operations.

Walter Roberson
Walter Roberson 2024 年 3 月 10 日
(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)

カテゴリ

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