MATLAB: How to plot (x,y,z) area

3d plotsplot

x + y + z = 3
x^2 + y^2 + z^2 = 6
(-10 <= x,y,z <= 10)
Plot (x,y,z) areas that satisfy the above two equations in 3 dimensions.

Best Answer

This is one of the solutions to such a problem
syms x y z
eq1 = x + y + z == 3;
eq2 = x^2 + y^2 + z^2 == 6;
sol = solve([eq1, eq2], [x, y]);
zv = linspace(-10, 10, 100000);
f = figure;
ax = axes();
hold(ax);
view(3);
for i=1:numel(sol.x)
xf = matlabFunction(sol.x(i));
yf = matlabFunction(sol.y(i));
xv = xf(zv);
yv = yf(zv);
idx1 = real(xv)==xv;
idx2 = real(yv)==yv;
idx = idx1 & idx2;
xv = xv(idx);
yv = yv(idx);
zv = zv(idx);
plot3(xv, yv, zv);
end