Dear Alan, could you please, explain more about the two vectors A and B. I don't understand the rationality of Error function you defined as sum((x-xc)^2+(y-yc)^2+(z-zc)^2-r^2)^2,. Is the initial sphere center is taken for partial of the error of each parameter for example xc= mean(x), yc=mean (y) and zc= mean (z) and the function E = sum((xi-mean(x))^2+(y-mean(y))^2+(z-mean(z))^2-r^2)^2 and then, minimze the function E. many thanks

Dear Alan, pointing to my previous comment, I have just want to correct the equation
E = sum((xi-mean(x))^2+(yi-mean (y))^2+(zi-mean(z))^2-r^2)^2
Regards