I have the following assignment which I have trouble implementing into Matlab. I get a result, but it's far from close enough to fit the data points. Here it is:
I have a bunch of data points for the function U:
U(150) = 2, U(200) = 3, U(300) = 4, U(500) = 5, U(1000) = 6, U(2000) = 7, U∞ = 8.
From that I’m supposed to use the Gauss-Newton method with the following anzats:
U_1(α) = 8 ? aα^b
With the Gauss-Newton method, which seeks to minimize the residue r(α)= 8 ? aα^b - U(α) for each of the seven points, I get a matrix r.
Then, as far as I understand, we set X^0 as an initial vector and start iterating according to the following (where D_r is the derivative of r with respect to both parameters a and b):
for k=0,1,2,..
A = D_r(x^k)
A'Av^k=-A'r(x^k) Here I solve for v^k
x^(k+1)= x^k + v^k
end
Which is supposed to improve upon the initial guess. Here comes my code so far:
Initial guess a=900 och b=-1
x = [900; -1]
A = [150; 200; 300; 500; 1000; 2000]
b = [2; 3; 4; 5; 6; 7]
D_r = zeros(6,2)
r = zeros(6,1)
z = [1:1000]
for j=1:5
for i=1:6
D_r(i,1) = A(i)^x(2)
D_r(i,2) = x(1)*x(2)*A(i)^(x(2)-1)
r(i) = (8-b(i)) - x(1)*A(i)^x(2)
end
v = D_r'*D_r(-D_r'*r)
x = x + v
end
U = 8 - x(1)*z.^(x(2));
plot(z, U), xlim([0 1000]), ylim([0 10])
Can anyone see where I'm wrong?
question from:
https://stackoverflow.com/questions/65869247/implementing-gauss-newton-method-in-matlab 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…