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

2 vues (au cours des 30 derniers jours)
Paul le 20 Juin 2021
Commenté : Paul le 25 Juin 2021
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.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponses (1)

Vimal Rathod le 23 Juin 2021
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 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Paul le 25 Juin 2021
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.

Connectez-vous pour commenter.

### Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

R2019b

### Community Treasure Hunt

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

Start Hunting!

Translated by