levernberg-marquadt method
Afficher commentaires plus anciens
So I am trying to make a Levernberg-Marquadt method in matlab. And I am somehow keep getting horzcat error.. Can someone help me fix the problem so that I can stop getting the horzcat error?
This is my code:
function [xc] = Lev_Mar(x0, lambda, max_it, Tol)
for i = 1:max_it
[r,A]=rdr_1(x0);
fprintf('x(%2d) = [%12.5e %12.5e %12.5e %12.5e %12.5e] E=%12.5e \n', i, x0, 0.5*r'*r );
AtA=A'*A;
v=-( AtA+lambda*diag(diag(AtA)) )\(A'*r);
x1 = x0+v;
if norm(v,inf) < Tol,
break;
end
x0=x1;
end
xc = x1;
%% END
%% For problem 1:
function [r, dr]=rdr_1(x)
t = [0 2 4 6 8 10 12 14 16 18 20 22 24]';
y = [1.00 3.95 5.33 4.59 3.35 2.35 1.72 1.36 1.18 1.08 1.04 1.02 1.01]';
E = exp(-x(4).*t);
f = (x(1)+x(2).*t.^(x(3)).*E);
r = f - y;
dr = [1, E.*t.^(x(3)), E.*x(2).*log(t).*t.^(x(3)), -E.*x(2).*t.^(x(3)+1)];
%% Plot the data points and the approximation curve
clf;
plot(t,y,'o'); hold on;
xp = [0:0.01:5]';
yp = x(1)+x(2).*xp.^(x(3)).*exp(-x(4).*xp);
plot(xp, yp, '-');
pause;
and my x0 = [1 1 2 0.5]; lambda = 0.01; max_it = 500; Tol = 10^-5
Réponses (1)
Matt J
le 12 Déc 2020
dr = [t.^0, E.*t.^(x(3)), E.*x(2).*log(t).*t.^(x(3)), -E.*x(2).*t.^(x(3)+1)];
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!