I don't know how to take the next step.

%8 to 15 meters is the range %Velocity is 0,15,30,45,60,75,90
clc,clear
V_o = input('Velocity at launch = ');
Theta = input('Elevation angle at launch = ');
a=-9.81; %Its a given
b=V_o*sind(Theta); %It makes the coding a bit less confusing.
c=0; %Also a given
fprintf('The velocity for the launch is %d meters per second. \n', V_o)
fprintf('The elevation angle for the launch is %d degrees. \n', Theta);
Q1=(-b-sqrt(b^2-4*a*c))/(a); %The 1/2 and times 2 cross out for the denom
disp(Q1)
%%Horizontal Range
H = V_o*cosd(Theta)*(Q1); fprintf('The Horizontal Range of the launch is %0.3f \n', H)
%% Vertical Height
V = (b^2)/(a*2)*2; fprintf('The Vertical Height of the launch is %0.3f \n', V)
%% Only input variable F to figure out the velocities and launch angles. T = menu ('Select the targeted distance','8','9','10','11','12','13','14','15');
if T == 8
Im trying to use the menu fuction to finish of my program, what information I need to find, which I have been unable for the past couple of days is, the formula. The menu function shall be the input to the second half of this program, Ive been stuck at this one part for days. (The input to this part of the program should be only the target distance. The output from this part of the program should be the velocities and launch angles for the projectile.)

 Risposta accettata

menu() returns the button number, not the button text like questdlg() does, so if they click the "8" button, it will return 1 and 9 will return 2, etc.. So you need to do this:
buttonNumber = menu ('Select the targeted distance','8','9','10','11','12','13','14','15');
T = buttonNumber + 7;

6 Commenti

By the way, it's in the help for menu() so there's no need to go days - just look at the help and solve it in seconds.
I understand the menu part thank you, but now I need to figure out how would I find the two outputs but just using one of the menu selections.
Colin, please read this
Now, have you written this "second half of the program" yet? If you have assigned the "velocities and launch angles for the projectile" then the program should just continue on and use those values. I'm not sure what the problem is. Can you step through it with the debugger to try to figure out why it's not stepping into the second half of the program?
If you haven't written it yet, then of course you need to do that first.
Collin Kerr
Collin Kerr il 24 Apr 2016
Modificato: Collin Kerr il 24 Apr 2016
(You will write a detailed MATLAB program that uses the projectile motion theory to compute the Horizontal range and Vertical Height of a launch for a user input velocity and elevation angle at launch.)(Completed) [Your program should also have a feature that predicts the velocities and elevation angles at which the projectile can be launched to hit a target given a specified distance. The input to this part of the program should be only the target distance. The output from this part of the program should be the velocities and launch angles for the projectile.]( Uncompleted) [Need help figuring out once given the input which is 8 through 15, how to get the two outputs needed.]
Since there are multiple solutions for any given distance, I'd probably create an image, say 1000 by 1000 where you use linspace(8,15,1000) to create the velocities and linspace(angle1, angle2, 1000). Then use meshgrid or have a double for loop over all possibilities. Then use contour() to show which velocity, angle pairs will give the required distance.
velocities = linspace(8, 15, 1000);
angles = linspace(10, 80, 1000);
[V, A] = meshgrid(velocities, angles);
distanceImage = some function of V and A.
imshow(distanceImage, []);
hold on;
contour(........
You can finish it. Please give it a try.
Ill be blunt, I have never seen any of those ways of coding before, due to this being my first year as an engineering student. I looked up how to use each one of those codes, but I went ahead and went a different route cause I did not understand your way. I was wondering if you could go ahead and finish the way you wanted me to? I already turned in the project, but im curious what your coding would have done. And what the finished product would have looked like. Thanks.

Accedi per commentare.

Più risposte (0)

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by