How can I plot a boundary between real and imaginary solutions in a 3D graph?

조회 수: 1 (최근 30일)
Paul
Paul 2021년 6월 20일
댓글: Paul 2021년 6월 25일
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.

답변 (1개)

Vimal Rathod
Vimal Rathod 2021년 6월 23일
Hi,
If you just want to connect points you could use the surf function on the x,y,z values obtained at the end. If you want to create just a boundary ignoring the inner points you could use the boundary function.
Hope this helps!
  댓글 수: 1
Paul
Paul 2021년 6월 25일
Hi Vimal,
Thanks for your answer. I wonder if there is an "optimal way" (without checking all the coordinates) to find the x,y,z values corresponding to the boundary. Because, without these values I can not use surf or boundary functions.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by