Using Euler's Method for projectile motion
์กฐํ ์: 55 (์ต๊ทผ 30์ผ)
์ด์ ๋๊ธ ํ์
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
๋๊ธ ์: 0
์ฑํ๋ ๋ต๋ณ
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
์ถ๊ฐ ๋ต๋ณ (0๊ฐ)
์ฐธ๊ณ ํญ๋ชฉ
์นดํ ๊ณ ๋ฆฌ
Help Center ๋ฐ File Exchange์์ Assembly์ ๋ํด ์์ธํ ์์๋ณด๊ธฐ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!