I have struggle with create a prompts for this can someone please help.

5 views (last 30 days)
The maximum horizontal distance, d, traveled by a projectile fired is calculated using the following formula ๐‘‘ = ๐‘ฃ ^2 /2๐‘” *( 1 + โˆš1 + 2๐‘” ๐‘ฆ0 /๐‘ฃ 2 sin2 ๐œƒ )๐‘ ๐‘–๐‘›2๐œƒ
Where โ€ข d is the total horizontal distance travelled by the projectile.
v is the velocity at which the projectile is launched
g is the gravitational acceleration: 9.81 ๐‘š/๐‘  2
ฮธ is the angle at which the projectile is launched
๐‘ฆ0 is the initial height of the projectile
Write a MATLAB program that prompts the user to input values for ๐‘ฃ and ๐‘ฆ0, and computes and outputs the distance ๐‘‘ for ๐œƒ = 10ยฐ, 15ยฐ, 20ยฐ, โ€ฆ , 40ยฐ. Note that when ๐‘ฆ0 = 0, the formula becomes ๐‘‘ = ๐‘ฃ 2 ๐‘” ๐‘ ๐‘–๐‘›2๐œƒ. Use this fact to test your implementation for the general case.
  9 Comments
Hong
Hong on 9 Feb 2024
Hi since the it just said sin20 in the textbook so i assume it should be radiant that's why i just put sin(20)
Image Analyst
Image Analyst on 10 Feb 2024
@Hong ๐‘ ๐‘–๐‘›2๐œƒ means "sine of two times theta (the angle)", not "sine of 20 radians" or "sin(20)".

Sign in to comment.

Answers (1)

Vaibhav
Vaibhav on 9 Feb 2024
Edited: Vaibhav on 9 Feb 2024
Hi Hong
I understand that you are facing issues in creating prompts to get input from the user.
You can consider using the "input" function to receive input from the user via MATLAB's command window. You can refer to the code snippet below:
% MATLAB program to compute projectile distance for various angles
% Clear variables and console
clear;
clc;
% Constants
g = 9.81; % Gravitational acceleration (m/s^2)
% Prompt user for input values
v = input('Enter the launch velocity v (m/s): ');
y0 = input('Enter the initial height y0 (m): ');
% Display the header for the output
fprintf('Angle (ยฐ)\tDistance (m)\n');
fprintf('-------------------------\n');
% Calculate and output the distance for angles 10ยฐ to 40ยฐ
for theta_deg = 10:5:40
% Convert angle from degrees to radians for computation
% Calculate the distance
% Output the distance for the current angle
end
You can refer to the MathWorks documentation below to learn more about "input" function:
Hope this helps!
  1 Comment
Hong
Hong on 9 Feb 2024
Hi,
Thanks for helping but i also have the problem on try to put the formula into matlab bc i keep getting the message that it can comput

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!