Reputation: 131
Given a set of datapoints I'm trying to approximate the coefficients a,b in the function U(x)=8-ax^b using Newtons method in MATLAB.
x = [150 200 300 500 1000 2000]';
y = [2 3 4 5 6 7]';
a=170; b=-0.7; iter = 0;
for iter=1:5
f=8-a*x.^(b) -y;
J = [-x.^b -a*b*x.^(b-1)]; %Jacobis matrix
h=J\f;
a=a-h(1); b=b-h(2);
disp(norm(f))
iter = iter+1;
end
The results are incorrect and I've not been sucessful of finding the misstep. All help is appreciated.
Upvotes: 1
Views: 349
Reputation:
Note that you can easily linearize your model with
Log(8 - U(x)) = Log(a) + b Log(x)
Upvotes: 0
Reputation: 20735
The jacobi matrix is wrong. Using Newton's method, you're trying to find the values of a
and b
that would solve the equations 8-ax^b - y = 0
. So, your Jacobi should be the derivatives of f
with respect to a
and b
. That is J = [df/da df/db]
, resulting in:
J = [-x.^b -a.*x.^b.*log(x)]
and you will get the following curve for the 5 iterations:
Upvotes: 2