Using Euler's Method for projectile motion

57 ビュー (過去 30 日間)
jcc
jcc 2022 年 11 月 1 日
コメント済み: jcc 2022 年 11 月 2 日
Problem statement: Write a program that employs the Euler method to compute the solution to the freely falling object. That is, calculate 𝑣 as a function of time. Consider different starting velocities over a time range from 𝑡 = 0 to 𝑡 = 10 s.
I'm not sure how to set up my time interval from 0-10 sec. I'm guessing "for j = t(1):dt:tf ". But not fully sure how to proceed. Any help would be appreciated. Thnak you.
What I have so far:
clear;
N = 100; % points to be taken
g = 9.8; % acceleration due to gravity (m/s^2)
dt = 0.01; % time step for time range of 1-10 sec.
theta = input('Angle of projection(in degrees): '); % Allows user to input
h = input('Initial height (in meters): ');
v_0 = input('Initial velocity (in m/s): ');
% Initial conditions below
x(1) = 0; % intial x position (m)
y(1) = h; % intial y position (m)
t(1) = 0; % inital time (s)
tf = 10; % final time (s)
v(1) = v_0; % initial velocity (m/s)
v_x = v_0*cos(theta); % "x" component of the velocity
v_y = v_0*sin(theta); % "y" component of the velocity
v_x(1) = v_x;
v_y(1) = v_y;
n = 1;
while n < N
% for statement here?
v(n+1)=sqrt((v_x(n)^2)+(v_y(n)^2));
v_x(n+1) = v_x(n);
v_y(n+1) = v_y(n) - g*dt;
x(n+1) = x(n) + v_x(n)*dt;
y(n+1) = y(n) + v_y(n)*dt;
if y(n+1)<0
n = N;
else
n = n+1;
end
end

採用された回答

Alan Stevens
Alan Stevens 2022 年 11 月 2 日
A little more like this? (I've used arbitrary values for initial conditions etc.)
N = 200; % points to be taken
g = 9.8; % acceleration due to gravity (m/s^2)
dt = 0.01; % time step for time range of 1-10 sec.
theta = 45; %input('Angle of projection(in degrees): '); % Allows user to input
h = 1; %input('Initial height (in meters): ');
v_0 = 5; %input('Initial velocity (in m/s): ');
% Initial conditions below
x(1) = 0; % intial x position (m)
y(1) = h; % intial y position (m)
t(1) = 0; % inital time (s)
tf = N*dt; % final time (s)
v(1) = v_0; % initial velocity (m/s)
v_x = v_0*cos(theta); % "x" component of the velocity
v_y = v_0*sin(theta); % "y" component of the velocity
v_x(1) = v_x;
v_y(1) = v_y;
n = 1;
for n = 1:N
v(n+1)=sqrt((v_x(n)^2)+(v_y(n)^2));
v_x(n+1) = v_x(n);
v_y(n+1) = v_y(n) - g*dt;
x(n+1) = x(n) + v_x(n)*dt;
y(n+1) = y(n) + v_y(n)*dt;
t(n+1) = t(n) + dt;
if y(n+1)<0
break
end
end
plot(x,y),grid
xlabel('x'),ylabel('y')
  3 件のコメント
Alan Stevens
Alan Stevens 2022 年 11 月 2 日
Set N = 10/dt
jcc
jcc 2022 年 11 月 2 日
ok, thank you for your help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAssembly についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by