What am I doing wrong here I keep getting a plot with either to many things on it or not enough all I want is a plot with two y axis and an x axis

1 view (last 30 days)
theta = 46.97;
theta2= 55;
v1= 13.5;
v2= 16.05;
x= (0:0.1:2.3);
x2= (0:0.1:5.14);
y= x*tan(theta)-(g/(2*v1.^2*cos(theta).^2))*x.^2;
y1= x2*tan(theta2)-(g/(2*v2.^2*cos(theta2).^2))*x2.^2;
yyaxis right
plot(x,y)
plot(x2,y1)
hold on

Accepted Answer

Alan Stevens
Alan Stevens on 13 Jan 2021
Like this
g = 9.81;
theta = 46.97;
theta2= 55;
v1= 13.5;
v2= 16.05;
x= (0:0.1:2.3);
x2= (0:0.1:5.14);
y= x*tan(theta)-(g/(2*v1.^2*cos(theta).^2))*x.^2;
y1= x2*tan(theta2)-(g/(2*v2.^2*cos(theta2).^2))*x2.^2;
plotyy(x,y,x2,y1),grid
  2 Comments
Alan Stevens
Alan Stevens on 13 Jan 2021
It worked for me! However, an alternative is
g = 32.2;
theta = 46.97;
theta2= 55;
v1= 13.5;
v2= 16.05;
x= (0:0.1:2.3);
x2= (0:0.1:5.14);
y= x*tan(theta)-(g/(2*v1.^2*cos(theta).^2))*x.^2;
y1= x2*tan(theta2)-(g/(2*v2.^2*cos(theta2).^2))*x2.^2;
plot(x,y),grid
ylabel('y')
yyaxis right
plot(x2,y1)
ylabel('y1')
xlabel('x')
This results in

Sign in to comment.

More Answers (0)

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!