What should I do? In an assignment A(:) = B, the number of elements in A and B must be the same.

1 回表示 (過去 30 日間)
%%it says that error is in the x(i+1) and y(i+1)
while norm(J) > e
I = [x(i),y(i)]';
syms h; % Step size
g = subs(f, [X,Y], [x(i)+S(1)*h,y(i)+h*S(2)]);
dg_dh = diff(g,h);
h = solve(dg_dh, h); % Optimal Step Length
x(i+1) = I(1)+h*S(1); % Updated x value
y(i+1) = I(2)+h*S(2); % Updated y value
i = i+1;
J = [subs(df_dx,[X,Y], [x(i),y(i)]) subs(df_dy, [X,Y], [x(i),y(i)])]; % Updated Gradient
S = -(J); % New Search Direction
end

採用された回答

darova
darova 2020 年 3 月 20 日
My solution
  3 件のコメント
darova
darova 2020 年 3 月 21 日
Maybe it takes values as symbolic. Try to convert into numeric
x(i+1) = I(1)+double(h(1))*S(1); % Updated x value
y(i+1) = I(2)+double(h(2))*S(2); % Updated y value
risky amalia
risky amalia 2020 年 3 月 22 日
thank you so much !!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

タグ

製品


リリース

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by