Graphing a hypersurface from two inequalities

5 vues (au cours des 30 derniers jours)
Ursula Trigos-Raczkowski
Ursula Trigos-Raczkowski le 25 Juil 2022
Réponse apportée : Ishu le 26 Oct 2023
I am trying to graph a hypersurface with inputs in mu_i, alpha_i, b_i space.
I tried to do this with a for loop but I am just getting what looks like a stack of 2D surfaces, which I don't think is correct.
Looking at a slice of this, varying only X (mu_i) and Y (alpha_i) I am getting a curved cone-like area, so I am expecting something like a curved 3D cone shape.
%% initializing constants
g = 2.5;
muj=18.5;
aj=7.6;
bj=23.3;
%% define range of alpha, bi and mui values
Z=linspace(bj,100); %bi
Y=linspace(aj,100); %alpha_i
X=linspace(0,muj); %mu_i
%% Making a Matrix of mu_i and alpha_i and b_i values
[m,a,b] = meshgrid(X,Y,Z);
%% Defining the two inequalities I want to graph the intersection of as a
%hypersurface
Sij= ((1/2).*b.*bj.^(-1).*(b+(-1).*g+(-1).*m).^(-1).*(bj+(-1).*g+(-1).*muj).*(g+muj).^(-1).*(g+m+muj).^(-1).*(2.*g+m+muj).*(g+2.*muj))<(a.^(-1).*aj);
Sji= (a.^(-1).*aj)<(2.*b.*bj.^(-1).*(b+(-1).*g+(-1).*m).^(-1).*(g+m).*(g+2.*m).^(-1).*(bj+(-1).*g+(-1).*muj).*(g+m+muj).*(2.*g+m+muj).^(-1));
feas = Sij.*Sji;
feas(feas==0) = NaN;
%% Graphing
fig1=figure();
hold on
for i =1:100 % not sure if this is right?
surf(m(:,:,i),a(:,:,i),b(:,:,i),feas(:,:,i),'DisplayName','Feasibility','EdgeColor', 'none', 'FaceColor','k','FaceAlpha',1)
end
xlabel('\mu_i , mortality sp i','FontSize',14)
ylabel('\alpha_i , senstivity sp i','FontSize',14)
zlabel('b_i, birth sp i','FontSize', 14)
Thank you, I would appreciate any tips.
I will attach the code varying only two of the variables here.
%% initializing constants
meshsize = .01;
g = 2.5;
muj=18.5;
aj=7.6;
bj=23.3;
bi=23.3;
%% define range of alpha and mu values
alphai=aj:meshsize:100;
mui=0:meshsize/4.995:muj;
%% Making a Matrix of mu_i and alpha_i values
[m,a] = meshgrid(mui,alphai);
%% Defining the inequalities I want to graph the intersection of
Sij= ((1/2).*bi.*bj.^(-1).*(bi+(-1).*g+(-1).*m).^(-1).*(bj+(-1).*g+(-1).*muj).*(g+muj).^(-1).*(g+m+muj).^(-1).*(2.*g+m+muj).*(g+2.*muj))<(a.^(-1).*aj);
Sji= (a.^(-1).*aj)<(2.*bi.*bj.^(-1).*(bi+(-1).*g+(-1).*m).^(-1).*(g+m).*(g+2.*m).^(-1).*(bj+(-1).*g+(-1).*muj).*(g+m+muj).*(2.*g+m+muj).^(-1));
feas = Sij.*Sji;
feas(feas==0) = NaN;
%% Graphing
fig1=figure();
surf(m,a,feas,'DisplayName','Feasibility','EdgeColor', 'none', 'FaceColor','k','FaceAlpha',1)
xlabel('\mu_i , mortality sp i','FontSize',14)
ylabel('\alpha_i , senstivity sp i','FontSize',14)

Réponses (1)

Ishu
Ishu le 26 Oct 2023
Hi Ursula,
I understand that you are trying to plot a hypersurface using "surf" function.
In your code you are using "hold on" before ant of the surface was plotted. In this case "hold on" by default assumes 2D axes and adjusts the surfaces according to that adn because of this you are getting a 2D plot instead of 3D plot.
You can change your code according to this:
fig1=figure();
for i =1:100 % not sure if this is right?
surf(m(:,:,i),a(:,:,i),b(:,:,i),feas(:,:,i),'DisplayName','Feasibility','EdgeColor', 'none', 'FaceColor','k','FaceAlpha',1)
hold on %shift hold on here
end
xlabel('\mu_i , mortality sp i','FontSize',14)
ylabel('\alpha_i , senstivity sp i','FontSize',14)
zlabel('b_i, birth sp i','FontSize', 14)
And as "surf" can only create a 3D surface plot, if you want to visualize more than 3D data, you can use "griddatan" to fit a hypersurface in 3D.
For more information on "griddatan: you can refer this documentation:
Hope it helps.

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by