MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   使用solve()和根多重性的问题 (https://www.labfans.com/bbs/showthread.php?t=22268)

poster 2019-11-29 07:37

使用solve()和根多重性的问题
 
为什么这不适用于Rosenbrock?它与测试功能一起使用。但是,如何使它与Rosenb一起使用?该错误是指h的解对于该函数不是唯一的。我该怎么办?

错误:“由于左侧和右侧具有不同数量的元素,因此无法执行分配。”

clc clear format long syms XY; %f = X - Y + 2*X^2 + 2*X*Y + Y^2; % Test function f= 100*(YX^2)^2+ (1-X)^2; %ROSENBROCK FUNCTION !!!!!!!!!!!!!!!!!!!!!!! x(1) = -1; y(1) = 4; e = 10^(-8); i = 1; % Gradient set up: df_dx = diff(f, X); df_dy = diff(f, Y); J = [subs(df_dx,[X,Y], [x(1),y(1)]) subs(df_dy, [X,Y], [x(1),y(1)])]; S = -(J); % Search Direction %Minimization Algorithm: while norm(J) > e I = [x(i),y(i)]'; syms h; 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); %Problem here!!!!!!!!!!!!!!!!!!!!! x(i+1) = I(1)+h*S(1); y(i+1) = I(2)+h*S(2); 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); end

[url=https://stackoverflow.com/q/59097071]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 19:43

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.