MATLAB Answers

trying to find theta

1 view (last 30 days)
% plot mountain
Mn_x = [0, 1000, 3014.8];
Mn_y = [0, 0, 616];
plot (Mn_x, Mn_y)
hold on
% known variables
Xo = 0;
Yo = 1;
V = 585; % m/s
G = 9.81; % m/s^2
t = linspace(0, 5, 900);
th1 = 10; % degrees
th2 = 12; % degrees
th3 = 14; % degrees
% calculate trajectory of howitzer
x_th1 = Xo + (V .* cosd(th1)) .* t;
y_th1 = Yo + (V .* sind(th1)) .* t - 1/2 .* G .* (t.^2);
plot (x_th1, y_th1, 'r')
x_th2 = Xo + (V .* cosd(th2)) .* t;
y_th2 = Yo + (V .* sind(th2)) .* t - 1/2 .* G .* (t.^2);
plot (x_th2, y_th2, 'k')
x_th3 = Xo + (V .* cosd(th3)) .* t;
y_th3 = Yo + (V .* sind(th3)) .* t - 1/2 .* G .* (t.^2);
plot (x_th3, y_th3, 'c')
xlim([-10 3250])
ylim([-10 650])
% calculate theta
theta = 0:1:90;
eqn = 3010 == Xo + (V .* cosd(theta)) .* t
I'm trying to find the theta value that makes the last equation true. when I run the code I recieve this error code
Arrays have incompatible sizes for this operation.
Error in lab2 (line 30)
eqn = 3010 == Xo + (V .* cosd(theta)) .* t

Accepted Answer

Star Strider
Star Strider on 21 Sep 2021
The Question lacks clarity.
% plot mountain
Mn_x = [0, 1000, 3014.8];
Mn_y = [0, 0, 616];
plot (Mn_x, Mn_y)
hold on
% known variables
Xo = 0;
Yo = 1;
V = 585; % m/s
G = 9.81; % m/s^2
t = linspace(0, 5, 900);
th1 = 10; % degrees
th2 = 12; % degrees
th3 = 14; % degrees
% calculate trajectory of howitzer
x_th1 = Xo + (V .* cosd(th1)) .* t;
y_th1 = Yo + (V .* sind(th1)) .* t - 1/2 .* G .* (t.^2);
plot (x_th1, y_th1, 'r')
x_th2 = Xo + (V .* cosd(th2)) .* t;
y_th2 = Yo + (V .* sind(th2)) .* t - 1/2 .* G .* (t.^2);
plot (x_th2, y_th2, 'k')
x_th3 = Xo + (V .* cosd(th3)) .* t;
y_th3 = Yo + (V .* sind(th3)) .* t - 1/2 .* G .* (t.^2);
plot (x_th3, y_th3, 'c')
xlim([-10 3250])
ylim([-10 650])
% calculate theta
% eqn = 3010 == Xo + (V .* cosd(theta)) .* t
theta_1 = interp1(x_th1, y_th1, 3010, 'pchip', 'extrap')
theta_2 = interp1(x_th2, y_th2, 3010, 'pchip', 'extrap')
theta_3 = interp1(x_th3, y_th3, 3010, 'pchip', 'extrap')
% I'm trying to find the theta value that makes the last equation true. when I run the code I recieve this error code
% Arrays have incompatible sizes for this operation.
% Error in lab2 (line 30)
% eqn = 3010 == Xo + (V .* cosd(theta)) .* t
It would appear that you want the ‘y_th#’ values for the corresponding ‘x_th#’ values that equal 3010. The only option is likely extrapolation using interp1. I have done that for all of them here. The θ values are fixed, and ‘t’ is a 900-element vector, and I have no idea if the θ values are supposed to be in terms of ‘t’ or something else.
Ambiguity of the context, and precise solutions are completely incompatible. Neverhteless, this provides an approach to a solution to consider in the event that my guess is incorrect.
.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!