Using Euler's Method for projectile motion

์กฐํšŒ ์ˆ˜: 55 (์ตœ๊ทผ 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 Exchange์—์„œ Assembly์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

์ œํ’ˆ


๋ฆด๋ฆฌ์Šค

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by