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!