Superimposing two 3 D surface plots
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
SM
el 29 de Abr. de 2024
Respondida: Chaitanya
el 10 de Mayo de 2024
I have multiple surface plots written using surf or mesh command. I now want to plot two or more surface plots in the same figure in order to show the difference between the two. For 2-D plots, its very straightforward. But I am unable to do so for 3D plots. Kindly help. I have given a sample code where u or U represents the two outputs to be plotted on the z- axis and x1 and x2 are the two input variables to be plotted on the x and y axes.Although u and U are different, the difference is not visible on the plot.
clc
clear all
close all
%tic
range=1;
resolution=0.1;
x1=-range:resolution:range;
x2=-range:resolution:range;
k=(range/resolution)*2+1;
h=1;
h1=1;
H=2;
H1=2;
A=1;
B=2;
for i=1:k;
for j=1:k;
if (x1(i)>=-h) && (x1(i)<=h) && (x2(j)>=-h1) && (x2(j)<=h1)
u(i,j)=-((2*A^2+5*A*B+2*B^2)*(x2(j)*h+x1(i)*h1))/(3*(A+B)*(x1(i)*x2(j)-3*h*h1));
else
u(i,j)=0;
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for q=1:k
for j=1:k
if (x1(q)>=-h) && (x1(q)<=h) && (x2(j)>=-h1) && (x2(j)<=h1)&& x2(j)<=(h1/h)*x1(q)
U(q,j)=-((x2(j)*h + x1(q)*h1)*((A - B)^2*x2(j)^2*(3*x1(q)^2 + h^2) -8*(A - B)*(2*A + B)*x2(j)*x1(q)*h*h1+((A - B)^2*x1(q)^2 - 3*(A + 3*B)*(7*A + 5*B)*h^2)*h1^2))/(24*h*h1*((A - B)*x2(j)^2*(x1(q)^2 + x1(q)*h + h^2)-x2(j)*((A - B)*x1(q)^2 + (A + 3*B)*h^2)*h1 +((A - B)*x1(q)^2 + (A + 3*B)*x1(q)*h + (A + 7*B)*h^2)*h1^2));
elseif (x1(q)>=-h) && (x1(q)<=h) && (x2(j)>=-h1) && (x2(j)<=h1)&& x2(j)>=(h1/h)*x1(q)
U(q,j)=-((x2(j)* h + x1(q)*h1)*((A - B)^2*x2(j)^2*(3*x1(q)^2 + h^2)-8*(A - B)*(2*A + B)*x2(j)*x1(q)*h*h1+((A - B)^2*x1(q)^2 - 3*(A + 3*B)*(7*A + 5*B)*h^2)*h1^2))/(24*h*h1*((A - B)*x2(j)^2*(x1(q)^2 - x1(q)*h + h^2)+x2(j)*((A - B)*x1(q)^2 + (A + 3*B)*h^2)*h1+((A - B)*x1(q)^2 - (A + 3*B)*x1(q)*h + (A + 7*B)*h^2)*h1^2));
else
U(q,j)=0;
end
end
end
% sUrf(x1,x2,U')
%mesh(x1,x2,U')
%Y14=u'-U';
mesh(x1,x2,u')
hold on
mesh(x1,x2,U')
xlabel('x1'), ylabel('x2'),zlabel('u or U')
2 comentarios
Respuesta aceptada
Chaitanya
el 10 de Mayo de 2024
Hello SM
I see that you are trying to superimpose 2 mesh plots.
The approach of setting ‘hold on’ is the correct way to super impose the 3D plots. However, in your case, both the plots are similar. Hence it seems as a 1 plot.
I was able to set different colors (red and blue) for the plot and was able to identify that the 2 plots.
Please refer to the code that I used and the corresponding output.
mesh(x1,x2,u','EdgeColor', 'r')
hold on
mesh(x1,x2,U','EdgeColor', 'b', 'FaceAlpha', 0.5)
xlabel('x1'), ylabel('x2'),zlabel('u or U')
Also refer to the following link for more information on mesh plots and setting different colors for the same.
Thanks,
Chaitanya
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!