I want to surface plot in the attachment. Also see my code.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
William Rose
am 10 Sep. 2023
Bearbeitet: William Rose
am 10 Sep. 2023
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 Kommentare
William Rose
am 10 Sep. 2023
Bearbeitet: William Rose
am 10 Sep. 2023
[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.
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!