I want to surface plot in the attachment. Also see my code.
1 次查看(过去 30 天)
显示 更早的评论
clear all;close all;
a = 1;
b = 2;
c = 2;
B = 3;
t = 1;
m = 0.5;
gamma = 0.8;
alpha = 0.9;
x = 0:0.01:10;
u = c*x.^gamma/gamma + (B*c^3)*(1+m^2)/(1-b*c^2*(1+m^2))*t^alpha/alpha;
u_1 = sqrt((-6*B*m^2*c^2*(1+(b*c^2*(1+m^2))/(1-b*c^2*(1+m^2))))/a)...
*jacobiSN(u,m);
plot(x,u_1);
grid on
figure(2)
surf([x; x], [u_1(1,:); u_1(1,:)], [zeros(size(x)); ones(size(x))])
grid on
4 个评论
回答(1 个)
William Rose
2023-9-10
编辑:William Rose
2023-9-10
The code you shared does not generate a dataset like the image you shared, so I am not sure exactly what you are trying to do. The code generates functions u(x) and u1(x), where x=0:.01:10. The your code plots u(x) versus u1(x), which is bascially a parametric plot, analogous to plotting x(t) versus y(t). The plot appears 3D because you plot it at levelz=0 and z=1, and you connect those with surf() so it looks like a ribbon oriented vertically. Your code is below along with the plots it generates. Beneath that, I will show you some code that generates a plot similar to the image you shared.
a = 1;
b = 2;
c = 2;
B = 3;
t = 1;
m = 0.5;
gamma = 0.8;
alpha = 0.9;
x = 0:0.01:10;
u = c*x.^gamma/gamma + (B*c^3)*(1+m^2)/(1-b*c^2*(1+m^2))*t^alpha/alpha;
u_1 = sqrt((-6*B*m^2*c^2*(1+(b*c^2*(1+m^2))/(1-b*c^2*(1+m^2))))/a)...
*jacobiSN(u,m);
plot(x,u_1);
grid on
figure(2)
surf([x; x], [u_1(1,:); u_1(1,:)], [zeros(size(x)); ones(size(x))])
grid on
Now for some code that generates a plot similar to the image you shared:
x=-12:.6:12; y=-12:.6:12;
[X,Y]=meshgrid(x,y);
Z=3*sin(2*pi*X/8+2*pi*Y/20);
surf(X,Y,Z,'FaceColor','m','EdgeColor','k');
xlabel('X'); ylabel('Y'); grid on; view(45,30)
Good luck.
6 个评论
William Rose
2023-9-10
编辑:William Rose
2023-9-10
[edit: change best to rest]
You're welcome.
Here is code that adds the rest of the box around the plot, as you requested. I have used a simplified surface example, but you scould use your equation for u_1(x) and get a similar result.
x=0:.2:10; z=-1.5*sin(2*pi*x/4.75);
figure
surf([x;x], [zeros(size(x));ones(size(x))],[z;z],'FaceColor','interp','EdgeColor','none');
hold on;
% add the actual data points
plot3(x,zeros(size(x)),z,'-r.',x,ones(size(x)),z,'-k.');
xlabel('X'); ylabel('Y'); zlabel('Z');
colorbar; view([37.5,30]); grid on; box on
% Now the code for the foreground edges of the box
axLim=[xlim;ylim;zlim]; % get axis limits
%make an array of the vertices needed to draw the box
boxVerts=[[axLim(1,1);axLim(2,1);axLim(3,2)],[axLim(1,2);axLim(2,1);axLim(3,2)],...
[axLim(1,2);axLim(2,1);axLim(3,1)],[axLim(1,2);axLim(2,1);axLim(3,2)],axLim(:,2)];
%draw the foreground edges of the box
plot3(boxVerts(1,:),boxVerts(2,:),boxVerts(3,:),'-k')
If the box were rotated about +-90 or 180 degrees, you would need to adjust the vertex list a bit. Good luck.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!