失效链接处理 |
matlab共轭梯度法 PDF 下载
本站整理下载:
相关截图:
主要内容:
function [result, x_result, num] = conjungate_gradient(f, x, x0, epsilon)
syms lambdas;
n = length(x);
nf = cell(1, n);
for i = 1 : n
nf{i} = diff(f, x{i});
end
nfv = subs(nf, x, x0);
nfv_pre = nfv;
count = 0;
k = 0;
xv = x0;
d = - nfv;
while (norm(nfv) > epsilon)
xv = xv+lambdas*d;
phi = subs(f, x, xv);
nphi = diff(phi);
lambda = solve(nphi);
lambda = double(lambda);
xv = subs(xv, lambdas, lambda);
xv = double(xv);
nfv = subs(nf, x, xv);
count = count + 1;
k = k + 1;
alpha = sumsqr(nfv) / sumsqr(nfv_pre);
d = -nfv + alpha * d;
nfv_pre = nfv;
if k >= n
k = 0;
d = - nfv;
end
|