Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
Hong
Hong el 9 de Feb. de 2024
Comentada: Image Analyst el 10 de Feb. de 2024
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 comentarios
Hong
Hong el 9 de Feb. de 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 el 10 de Feb. de 2024
@Hong 𝑠𝑖𝑛2𝜃 means "sine of two times theta (the angle)", not "sine of 20 radians" or "sin(20)".

Iniciar sesión para comentar.

Respuestas (1)

Vaibhav
Vaibhav el 9 de Feb. de 2024
Editada: Vaibhav el 9 de Feb. de 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 comentario
Hong
Hong el 9 de Feb. de 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

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by