I want to surface plot in the attachment. Also see my code.
Show older comments
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 Comments
Dyuman Joshi
on 10 Sep 2023
Your code is working.
What do you want to do? Get the exact same orientation as the image attached?
Farooq Aamir
on 10 Sep 2023
Dyuman Joshi
on 10 Sep 2023
What equations did you use to get the graph using Mathematica?
Farooq Aamir
on 10 Sep 2023
Answers (1)
William Rose
on 10 Sep 2023
Edited: William Rose
on 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 Comments
Farooq Aamir
on 10 Sep 2023
Torsten
on 10 Sep 2023
figure(2)
surf([x; x], [zeros(size(x)); ones(size(x))],[u_1(1,:); u_1(1,:)],'FaceColor','interp','EdgeColor','none');
view([37.5 30])
colorbar
Farooq Aamir
on 10 Sep 2023
William Rose
on 10 Sep 2023
Edited: William Rose
on 10 Sep 2023
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);
figure(2)
surf([x; x], [zeros(size(x)); ones(size(x))],[u_1(1,:); u_1(1,:)],...
'FaceColor','interp','EdgeColor','none');
view([37.5 30])
colorbar
xlabel('X'); ylabel('Y'); zlabel('Z');
box on % Add box frame
hold on; plot3(x,zeros(size(x)),u_1,'-r.');
plot3(x,ones(size(x)),u_1,'-k.');
Understand the plot: you have plotted x versus u_1(x) at y=0 (red), and you have plotted the same set of points (x versus u_1(x)) at y=1 (black), and you have drawn a sheet connecting them. This makes a 2-d plot look 3-dimensional, but it is not 3-d data. At least that's how I view it.
Farooq Aamir
on 10 Sep 2023
William Rose
on 10 Sep 2023
Edited: William Rose
on 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.
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





