Hey so I am trying to code an ellipse and I was confused about the placement of my plot. Should it be before the for loop or after?

3 Ansichten (letzte 30 Tage)
% Given Variables
a= 20; % Meters (m)
b=10; % Meters (m)
h=18; % Meters (m)
n=5;
t=0:0.01 : 2*pi*n;
% Calculations
r= (((a*b)./(sqrt(b*cos (t)).^2))+(a*sin(t).^2)) ;
x= (r .*cos(t));
y= (r.*sin(t));
z= ((h*t)./(2*pi*n)) ;
% Plotting plot 3
figure(1)
plot3 (x,y,z)
title('A ellispe')
xlabel('x')
ylabel('y')
zlabel('z')
grid on
% Loop for N=3
N=3;
for k=1:1:N
a2= 20*k; % Meters (m)
b2= 10*k;% Meters (m)
h2=18*k;% in Meters (m)
n=5;
t=0:0.01:2*pi*n;
r2= (((a2*b2)./(sqrt (b2*cos (t)).^2))+ (a2*sin(t).^2)) ;
x2= (r2.*cos (t));
y2= (r2.*sin(t));
z2= ((h2*t)./ (2*pi*n)) ;
% Define Meshgrid
[xx,yy]= meshgrid(x2, y2);
zz=xx.^2-yy.^2;
% Plotting
figure(2)
plot3 (x2 ,y2 , z2)
mesh(xx, yy, zz)
title(' A ellispe function')
xlabel( 'x=r*cos (t) ')
ylabel('y=r*sin(t)')
zlabel('= (h*t)./ (2*pi*n) ')
grid on
hold on
end
  1 Kommentar
Eshan Patel
Eshan Patel am 2 Nov. 2022
In order for the community to help, could you please give more information about the plot you are expecting? You can include the following information:
  1. Why are you using 3D axis to plot an ellipse?
  2. How do you want the plot to behave in 3-D?
  3. What equation are you using to plot the ellipse?
  4. What does your expected plot look like?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Alan Stevens
Alan Stevens am 2 Nov. 2022
Something like this? (I've commented out your meshgrid commands as they just confuse the plot and I'm not at all clear why they are there - you can easily reinstate them if you wish).
% Given Variables
a= 20; % Meters (m)
b=10; % Meters (m)
h=18; % Meters (m)
n=5;
t=0:0.01:2*pi*n;
% Calculations
r= a*b./sqrt( (b*cos(t)).^2+(a*sin(t)).^2 ) ;
x= (r.*cos(t));
y= (r.*sin(t));
z= ((h*t)./(2*pi*n)) ;
% Plotting plot 3
figure(1)
plot3 (x,y,z)
title('An ellipse')
xlabel('x')
ylabel('y')
zlabel('z')
grid on
% Loop for N=3
figure(2)
N=3;
for k=1:N
a2= 20*k; % Meters (m)
b2= 10*k;% Meters (m)
h2=18*k;% in Meters (m)
r2= a2*b2./sqrt( (b2*cos(t)).^2+(a2*sin(t)).^2 ) ;
x2= (r2.*cos (t));
y2= (r2.*sin(t));
z2= ((h2*t)./ (2*pi*n)) ;
% Define Meshgrid
% [xx,yy]= meshgrid(x2, y2);
% zz=xx.^2-yy.^2;
% Plotting
plot3 (x2 ,y2 , z2)
% mesh(xx, yy, zz)
title(' A ellipse function')
xlabel( 'x=r*cos (t) ')
ylabel('y=r*sin(t)')
zlabel('= (h*t)./ (2*pi*n) ')
grid on
hold on
end

Kategorien

Mehr zu 2-D and 3-D 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!

Translated by