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!