# Non linear system using Gauss Newton

I'm trying to solve this question whose growth function is given as: Pk = (r^k) * P0

Where pk = [0.19 0.36 0.69 1.3 2.5 4.7 8.5 14]

k = [1 2 3 4 5 6 7 8]

The unknowns I'm trying to solve for is r and p0.

So what I've done is to compute the residual as residual = Pk - (r^k) * p0

then compute the Jacobian and do Gauss Newton Method as shown below, but it doesnt converge to the answer that I want which is r = 1.8642 p0 = 0.1058. Instead it converges to p0 = 0.1616 and r = 1.7494. I'm wondering where I went wrong

clear all;
r= 1.8;
p0 = 0.1;

for i = 1:4
residual = [
0.19 - (r^1)*p0;
0.36 - (r^2)*p0
0.69 - (r^3)*p0
1.30 - (r^4)*p0
2.50 - (r^5)*p0
4.70 - (r^6)*p0
8.50 - (r^7)*p0
14.0 - (r^8)*p0];
dfdp0 =    [ -r^1
-r^2
-r^3
-r^4
-r^5
-r^6
-r^7
-r^8];
dfdr =        [-1*p0*r^0
-2*p0*r^1
-3*p0*r^2
-4*p0*r^3
-5*p0*r^4
-6*p0*r^5
-7*p0*r^6
-8*p0*r^7
];
J = [dfdr,dfdp0];
z = [r; p0]
temp = -J\residual;
z = z + temp
r= z(1);
p0 = z(2);
end

New contributor
s878 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
• You minimize the value of your residual vector $J=\sqrt{\sum_k r_k^2}$ with $r_k$ in your text. Calculate $J$ with your expected value for $r$, $p0$ and that of the obtained solution. You will see, that the obtained solution has a overall smaller value $J$. – Bort Dec 5 at 10:12