I have struggle with create a prompts for this can someone please help.
1 次查看(过去 30 天)
显示 更早的评论
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.
回答(1 个)
Vaibhav
2024-2-9
编辑:Vaibhav
2024-2-9
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!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!