code for ploting the trajectories of hyperbola parabola and ellipse in matlab

To plot the trajectories of hyperbola, parabola and ellipse in matlab, you need to define their equations and then use the "plot" command. Here's how you can do it:

Hyperbola

main.m
% Define the hyperbola equation
x = -10:0.01:10;
a = 2;
b = 3;
y = sqrt((b^2/a^2)*(x.^2-a^2)) ;
y1 = -sqrt((b^2/a^2)*(x.^2-a^2));

% Plot the hyperbola
plot(x, y, 'r');
hold on;
plot(x, y1, 'r');
grid on;

% Add labels and title
xlabel('X-axis');
ylabel('Y-axis');
title('Hyperbola Trajectory');
296 chars
18 lines

Parabola

main.m
% Define the parabola equation
x = -10:0.01:10;
a = 2;
y = x.^2/(4*a);

% Plot the parabola
plot(x, y, 'b');
grid on;

% Add labels and title
xlabel('X-axis');
ylabel('Y-axis');
title('Parabola Trajectory');
208 chars
14 lines

Ellipse

main.m
% Define the ellipse equation
x = -10:0.01:10;
a = 2;
b = 3;
y = sqrt((1-(x.^2/a^2))*b^2);
y1 = -sqrt((1-(x.^2/a^2))*b^2);

% Plot the ellipse
plot(x, y, 'g');
hold on;
plot(x, y1, 'g');
grid on;

% Add labels and title
xlabel('X-axis');
ylabel('Y-axis');
title('Ellipse Trajectory');
285 chars
18 lines

Note: You can modify the values of "a" and "b" in each equation to change the shape and size of the curves.

gistlibby LogSnag