Gauss-Newton method

GaussNewton[r_,p0_,tol_,stop_]:=(
iter=0;
temp=If[Length[p0]==1,{},Table[0,Length[p0]-1]];
ϵ=(10^(-7));
Jacobi[p_]:=Table[((r[p+Insert[temp,ϵ,j]][[i]]-r[p][[i]])/ϵ),{i,1,Length[r[p]]},{j,1,Length[p]}]//Simplify;
pOld=p0;
pNew=p0+Table[1,{i,Length[p0]}];

While[Norm[pOld-pNew]>tol && iter≤stop ,
pOld=pNew;
Δp=LeastSquares[Jacobi[pOld],-r[pOld]];
α=1;
pNew=pOld+α Δp;
While[Norm[r[pNew],2]>Norm[r[pOld],2],
α/=2;
pNew=pOld+α Δp;
];
iter++;
];
pNew
)

Logistic function

(*Logistic function parameters estimation*)
y={0.04,0.35,1.05,1.9,1.98,1.97,1.99,1.999};
f[t_,p_]:=((p[[1]])/((1-((p[[1]])/(p[[3]])))E^(-p[[2]] t)+((p[[1]])/(p[[3]]))));
error[p_]:=f[Range[0,7,1],p]-y;
tol=(10^(-6));
stop=100;
result=GaussNewton[error,{1,1.2,1},tol,stop]

Show[ListPlot[{0.04,0.35,1.05,1.9,1.98,1.97,1.99,1.999}],Plot[f[t,result],{t,0,8},PlotStyle-> Red]]

MEMS accelerometers problem

rawData={{-11718.`,966306.`,31738.`},{-14648.`,938278.4`,209862.4`},{-17577.8`,891403.8`,365428.2`},{-21386.4`,815134.2`,519431.4`},{-26171.4`,710251.8`,662986.2`},{-31151.4`,583006.`,778122.8`},{-37109.`,440330.4`,874997.`},{-42675.2`,277831.`,941500.8`},{-47851.`,112108.8`,983199.8`},{-53124.4`,-58593.`,993258.6`},{271343.5714285714`,488907.4285714286`,780340.7142857143`},{494627.`,249413.`,780759.`},{566795.2`,-59472.2`,779294.`},{474412.4`,-366600.4`,775680.8`},{239842.6`,-586619.2`,771286.8`},{-80956.4`,-656833.6`,766696.6`},{-378986.3333333333`,-561766.`,763750.5`},{-597068.4`,-326463.8`,763278.6`},{-668943.`,-8984.2`,765623.`},{-573533.4`,296189.8`,769626.6`},{-337498.6`,513182.`,774020.8`},{-503904.`,852243.2`,22851.`},{-884177.2`,491209.`,13671.`},{-1.028903`*^6,4979.8`,7324.`},{-917673.2`,-493357.6`,4296.4`},{-562888.4`,-874118.4`,5371.`},{-69432.8`,-1.0236296`*^6,9277.`},{413377.6`,-911911.4`,16698.6`},{787302.2`,-571872.8`,24804.4`},{943681.8333333334`,-52815.333333333336`,31167.666666666668`},{830889.3333333334`,433998.8333333333`,34504.333333333336`},{483494.6`,812399.4`,33788.6`}};
g=9.81;
axhat={-1.028903`*^6,4979.8`,7324.`};
ayhat={-69432.8`,-1.0236296`*^6,9277.`};
azhat={-53124.4`,-58593.`,993258.6`};
initial={9.`*10^-6,0,0.,-2.828363943901612`*^-7,-7.00345578266001`*^-6,0,-2.743501000251762`*^-7,2.1338341113069259`*^-7,-1.000957963396124`*^-6,0.7,0.7,0.2};

M[p_]:={{p[[1]],p[[2]],p[[3]]},{p[[4]],p[[5]],p[[6]]},{p[[7]],p[[8]],p[[9]]}};
b[p_]:={p[[10]],p[[11]],p[[12]]};
error[p_]:= Join[(M[p].axhat+b[p]-{g,0,0})/g,(M[p].ayhat+b[p]-{0,g,0})/g,(M[p].azhat+b[p]-{0,0,g})/g,Table[Norm[M[p].rawData[[i]]+b[p]]-g,{i,1,Dimensions[rawData][[1]]}]];
stop=50;
tol=(10^(-9));
GaussNewton[error,initial,tol,stop]

(*Check whether the parameters satisfy the condition for the vectors and the gravitational acceleration*)

Join[{Norm[M[pNew].axhat+b[pNew]]},{Norm[M[pNew].ayhat+b[pNew]]},{Norm[M[pNew].azhat+b[pNew]]},Table[Norm[{M[pNew].rawData[[i]]+b[pNew]}],{i,Dimensions[rawData][[1]]}]]