How can I plot a boundary between real and imaginary solutions in a 3D graph?
1 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I have a function of three variables and I would like to plot a 3D graph where you can see the boundary (a surface or any shape) that separates the real and imaginary solutions of the function for a certain input. How can I do it?
So far, I have the following code:
fun = @(psi,theta,x)sqrt(-1.0./((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2-sqrt((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2-((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(2.5e1./9.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2.*(2.5e1./9.0)+(cos(psi).*(3.0./2.0e1)-3.0./2.0e1).^2.*(2.5e1./9.0)).^2+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2).*(sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2-((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(2.5e1./9.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2.*(2.5e1./9.0)+(cos(psi).*(3.0./2.0e1)-3.0./2.0e1).^2.*(2.5e1./9.0)).*(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0)).^2.*((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2-sqrt((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2-((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(2.5e1./9.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2.*(2.5e1./9.0)+(cos(psi).*(3.0./2.0e1)-3.0./2.0e1).^2.*(2.5e1./9.0)).^2+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2).*(sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0)-((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(2.5e1./9.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2.*(2.5e1./9.0)+(cos(psi).*(3.0./2.0e1)-3.0./2.0e1).^2.*(2.5e1./9.0)).^2+((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(2.5e1./9.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2.*(2.5e1./9.0)+(cos(psi).*(3.0./2.0e1)-3.0./2.0e1).^2.*(2.5e1./9.0)).*(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0)).^2+1.0).*(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(9.0./5.0e1)-sqrt((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2-((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(2.5e1./9.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2.*(2.5e1./9.0)+(cos(psi).*(3.0./2.0e1)-3.0./2.0e1).^2.*(2.5e1./9.0)).^2+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2).*(sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).*(9.0./5.0e1)-((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(2.5e1./9.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2.*(2.5e1./9.0)+(cos(psi).*(3.0./2.0e1)-3.0./2.0e1).^2.*(2.5e1./9.0)).^2.*(9.0./5.0e1)+((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(2.5e1./9.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2.*(2.5e1./9.0)+(cos(psi).*(3.0./2.0e1)-3.0./2.0e1).^2.*(2.5e1./9.0)).*(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).*(9.0./5.0e1))./((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2-sqrt((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2-((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(2.5e1./9.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2.*(2.5e1./9.0)+(cos(psi).*(3.0./2.0e1)-3.0./2.0e1).^2.*(2.5e1./9.0)).^2+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2).*(sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2-((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(2.5e1./9.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2.*(2.5e1./9.0)+(cos(psi).*(3.0./2.0e1)-3.0./2.0e1).^2.*(2.5e1./9.0)).*(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0))-1.0./5.0)+(((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2-sqrt((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2-((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(2.5e1./9.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2.*(2.5e1./9.0)+(cos(psi).*(3.0./2.0e1)-3.0./2.0e1).^2.*(2.5e1./9.0)).^2+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2).*(sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0)-((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(2.5e1./9.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2.*(2.5e1./9.0)+(cos(psi).*(3.0./2.0e1)-3.0./2.0e1).^2.*(2.5e1./9.0)).^2+((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(2.5e1./9.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2.*(2.5e1./9.0)+(cos(psi).*(3.0./2.0e1)-3.0./2.0e1).^2.*(2.5e1./9.0)).*(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0)).*(sin(theta).*(1.0e1./9.0)-cos(theta).*sin(psi).*(1.0e1./9.0)+sqrt(-1.0./((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2-sqrt((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2-((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(2.5e1./9.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2.*(2.5e1./9.0)+(cos(psi).*(3.0./2.0e1)-3.0./2.0e1).^2.*(2.5e1./9.0)).^2+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2).*(sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2-((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(2.5e1./9.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2.*(2.5e1./9.0)+(cos(psi).*(3.0./2.0e1)-3.0./2.0e1).^2.*(2.5e1./9.0)).*(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0)).^2.*((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2-sqrt((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2-((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(2.5e1./9.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2.*(2.5e1./9.0)+(cos(psi).*(3.0./2.0e1)-3.0./2.0e1).^2.*(2.5e1./9.0)).^2+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2).*(sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0)-((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(2.5e1./9.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2.*(2.5e1./9.0)+(cos(psi).*(3.0./2.0e1)-3.0./2.0e1).^2.*(2.5e1./9.0)).^2+((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(2.5e1./9.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2.*(2.5e1./9.0)+(cos(psi).*(3.0./2.0e1)-3.0./2.0e1).^2.*(2.5e1./9.0)).*(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0)).^2+1.0)-1.0e1./9.0).*(9.0./5.0e1))./((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2-sqrt((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2-((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(2.5e1./9.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2.*(2.5e1./9.0)+(cos(psi).*(3.0./2.0e1)-3.0./2.0e1).^2.*(2.5e1./9.0)).^2+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2).*(sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2-((sin(theta).*(-1.0./5.0)+cos(theta).*sin(psi).*(1.0./5.0)+1.0./5.0).^2.*(2.5e1./9.0)+(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0).^2.*(2.5e1./9.0)+(cos(psi).*(3.0./2.0e1)-3.0./2.0e1).^2.*(2.5e1./9.0)).*(x+cos(theta).*(1.0./5.0)+sin(psi).*sin(theta).*(1.0./5.0)-1.0./5.0));
% Input values:
psi = linspace(-pi/6,pi/6,50); theta = linspace(-pi/6,pi/6,50);x = linspace(0,0.5,50);
[PSI,THETA,X] = meshgrid(psi,theta,x);
% Solution for a certain input:
solution = fun(PSI,THETA,X);
% Obtain only the coordinates of real solutions and assign value
% "0" to imaginary solutions and value "1" to real ones.
coord_1 = [];
coord_2 = [];
coord_3 = [];
l = 1;
for i=1:length(psi)
for j=1:length(theta)
for k=1:length(x)
if imag(solution(i,j,k)) == 0
solution(i,j,k) = 1;
coord_1(l) = PSI(i,j,k);
coord_2(l) = THETA(i,j,k);
coord_3(l) = X(i,j,k);
l=l+1;
else
solution(i,j,k) = 0;
end
end
end
end
scatter3(coord_1',coord_2',coord_3',2);
By boundary I mean something similar to plot only the outer points (connected each other) of the scatter3 graph.
Thank you in advance.
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!