function threespheres(x0, C1, C2, C3, R1, R2, R3)

% Plots 3 spheres i = 1:3 with centers at Ci and radii Ri.
% Also plots the intersection point found by fsolve
% using the objective function given in spheres.m.
% Input x0 is the initial guess for the intersection.

[X, Y, Z] = sphere(20);
surf(R1*X+C1(1), R1*Y+C1(2), R1*Z+C1(3), 'FaceColor', 'w');
hold on
surf(R2*X+C2(1), R2*Y+C2(2), R2*Z+C2(3), 'FaceColor', 'w');
surf(R3*X+C3(1), R3*Y+C3(2), R3*Z+C3(3), 'FaceColor', 'w');
axis equal
camlight

options = optimset('LargeScale', 'Off');
x = fsolve(@spheres, x0, options, C1, C2, C3, R1, R2, R3);
plot3(x(1), x(2), x(3), 'ro', 'MarkerSize', 10, 'MarkerFaceColor', 'r')