Solve a system of equations
Show older comments
How can I find the x and y of the point with minimum z which lies on the intersection of a sphere and a plane? Sphere's equation: x^2+y^2+z^2=16 Plane's equation: x+y+z=0
1 Comment
Ryan Takatsuka
on 21 Jul 2018
To find the intersection of these 2 equations, they must be equated to each other. Solve the plane equation for z and square the equation:
z = -x - y
z^2 = x^2 + 2xy + y^2
Now solve the sphere equation for z^2:
z^2 = 16 - y^2 - x^2
Now these equations can be equated to each other:
x^2 + 2xy + y^2 = 16 - y^2 - x^2
Solving for y results in the equation of an ellipse (it makes sense that the intersection of a sphere and plane would be an ellipse):
y = 0.5 * (-sqrt(32-3x^2) - x)
y = 0.5 (sqrt(32-3x^2) - x)
Now just plug this equation back into the original plane or sphere equation to find all of the z values. Then find the minimum.
% Create The x vector
x = linspace(-5,5,10000);
% The ellipse equation (positive and negative versions)
y_pos = 0.5 * (sqrt(32 - 3*x.^2) - x);
y_neg = 0.5 * (-sqrt(32 - 3*x.^2) - x);
% Remove the complex values (no imaginary values)
k = 1;
for i=1:length(x)
if isreal(y_pos(i))
y_real(k) = y_pos(i);
x_real(k) = x(i);
k = k+1;
end
end
for i=1:length(x)
if isreal(y_neg(i))
y_real(k) = y_neg(i);
x_real(k) = x(i);
k = k+1;
end
end
% Plot the ellipse
figure
scatter(x_real, y_real)
% Calculate the z values
z = -x_real - y_real;
% Find the minimum
min(z)
Answers (0)
Categories
Find more on Quantum Chemistry in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!